Skip to content

Commit

Permalink
fix: log crejsonldap stderr, do NOT parse it as JSON (GLPI UP1#168946)
Browse files Browse the repository at this point in the history
  • Loading branch information
prigaux committed Nov 25, 2024
1 parent 90e32c1 commit 37139a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/crejsonldap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const call = (v: v, opts: options) => {
}

// exported for tests purpose
export const callRaw = { fn: (param: string) => utils.popen(param, 'createCompte', []) };
export const callRaw = { fn: (param: string) => utils.popen(param, 'createCompte', [], { log_stderr: true }) };

export const throw_if_err = (resp: resp) => {
const err = resp.err && resp.err[0];
Expand Down
5 changes: 3 additions & 2 deletions server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,18 @@ export const wait = (milliseconds: number) => (

import { spawn } from 'child_process';

export function popen(inText: string, cmd: string, params: string[]): Promise<string> {
export function popen(inText: string, cmd: string, params: string[], opts?: { log_stderr?: true }): Promise<string> {
let p = spawn(cmd, params);
p.stdin.write(inText);
p.stdin.end();

return <Promise<string>> new Promise((resolve, reject) => {
let output = '';
let get_ouput = (data: any) => { output += data; };
let error_log = (data: any) => console.error(`${cmd} stderr : ${data}`)

p.stdout.on('data', get_ouput);
p.stderr.on('data', get_ouput);
p.stderr.on('data', opts?.log_stderr ? error_log : get_ouput);
p.on('error', event => {
reject(event);
});
Expand Down

0 comments on commit 37139a1

Please sign in to comment.