File tree Expand file tree Collapse file tree 3 files changed +28
-10
lines changed Expand file tree Collapse file tree 3 files changed +28
-10
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
19
19
} from "./distribution" ;
20
20
import {
21
21
assertNever ,
22
+ getChildProcessErrorMessage ,
22
23
getErrorMessage ,
23
24
getErrorStack ,
24
25
} from "../common/helpers-pure" ;
@@ -547,9 +548,7 @@ export class CodeQLCliServer implements Disposable {
547
548
yield JSON . parse ( event ) as EventType ;
548
549
} catch ( err ) {
549
550
throw new Error (
550
- `Parsing output of ${ description } failed: ${
551
- ( err as any ) . stderr || getErrorMessage ( err )
552
- } `,
551
+ `Parsing output of ${ description } failed: ${ getErrorMessage ( err ) } ` ,
553
552
) ;
554
553
}
555
554
}
@@ -647,9 +646,7 @@ export class CodeQLCliServer implements Disposable {
647
646
return JSON . parse ( result ) as OutputType ;
648
647
} catch ( err ) {
649
648
throw new Error (
650
- `Parsing output of ${ description } failed: ${
651
- ( err as any ) . stderr || getErrorMessage ( err )
652
- } `,
649
+ `Parsing output of ${ description } failed: ${ getErrorMessage ( err ) } ` ,
653
650
) ;
654
651
}
655
652
}
@@ -1647,7 +1644,7 @@ export async function runCodeQlCliCommand(
1647
1644
return result . stdout ;
1648
1645
} catch ( err ) {
1649
1646
throw new Error (
1650
- `${ description } failed: ${ ( err as any ) . stderr || getErrorMessage ( err ) } ` ,
1647
+ `${ description } failed: ${ getChildProcessErrorMessage ( err ) } ` ,
1651
1648
) ;
1652
1649
}
1653
1650
}
Original file line number Diff line number Diff line change @@ -67,3 +67,26 @@ export function asError(e: unknown): Error {
67
67
68
68
return e instanceof Error ? e : new Error ( String ( e ) ) ;
69
69
}
70
+
71
+ /**
72
+ * Get error message when the error may have come from a method from the `child_process` module.
73
+ */
74
+ export function getChildProcessErrorMessage ( e : unknown ) : string {
75
+ return isChildProcessError ( e ) ? e . stderr : getErrorMessage ( e ) ;
76
+ }
77
+
78
+ /**
79
+ * Error thrown from methods from the `child_process` module.
80
+ */
81
+ interface ChildProcessError {
82
+ readonly stderr : string ;
83
+ }
84
+
85
+ function isChildProcessError ( e : unknown ) : e is ChildProcessError {
86
+ return (
87
+ typeof e === "object" &&
88
+ e !== null &&
89
+ "stderr" in e &&
90
+ typeof e . stderr === "string"
91
+ ) ;
92
+ }
Original file line number Diff line number Diff line change @@ -54,9 +54,7 @@ export async function sarifParser(
54
54
} ) ;
55
55
} catch ( e ) {
56
56
throw new Error (
57
- `Parsing output of interpretation failed: ${
58
- ( e as any ) . stderr || getErrorMessage ( e )
59
- } `,
57
+ `Parsing output of interpretation failed: ${ getErrorMessage ( e ) } ` ,
60
58
) ;
61
59
}
62
60
}
You can’t perform that action at this time.
0 commit comments