Skip to content

Commit 7b9b6a9

Browse files
committed
fix(utils): hide verbose stdout/stderr attributes in ProcessError object
1 parent ad2ae82 commit 7b9b6a9

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

packages/utils/src/lib/execute-process.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import ansis from 'ansis';
21
import {
32
type ChildProcess,
43
type ChildProcessByStdio,
@@ -28,9 +27,11 @@ export type ProcessResult = {
2827
/**
2928
* Error class for process errors.
3029
* Contains additional information about the process result.
30+
*
3131
* @example
32-
* const result = await executeProcess({}).catch((error) => {
32+
* const result = await executeProcess({ ... }).catch((error) => {
3333
* if (error instanceof ProcessError) {
34+
* console.error(error.message);
3435
* console.error(error.code);
3536
* console.error(error.stderr);
3637
* console.error(error.stdout);
@@ -39,18 +40,31 @@ export type ProcessResult = {
3940
*
4041
*/
4142
export class ProcessError extends Error {
43+
bin: string;
4244
code: number | null;
43-
stderr: string;
44-
stdout: string;
45+
signal: NodeJS.Signals | null;
46+
// attributes hidden behind getters so they're not printed in uncaught errors (too verbose)
47+
#stdout: string;
48+
#stderr: string;
4549

4650
constructor(result: ProcessResult) {
4751
const message = result.signal
48-
? `Process ${ansis.bold(result.bin)} terminated by ${result.signal}`
49-
: `Process ${ansis.bold(result.bin)} failed with exit code ${result.code}`;
52+
? `Process terminated by ${result.signal}`
53+
: `Process failed with exit code ${result.code}`;
5054
super(message);
55+
this.bin = result.bin;
5156
this.code = result.code;
52-
this.stderr = result.stderr;
53-
this.stdout = result.stdout;
57+
this.signal = result.signal;
58+
this.#stdout = result.stdout;
59+
this.#stderr = result.stderr;
60+
}
61+
62+
get stdout() {
63+
return this.#stdout;
64+
}
65+
66+
get stderr() {
67+
return this.#stderr;
5468
}
5569
}
5670

0 commit comments

Comments
 (0)