File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
1919} from "./distribution" ;
2020import {
2121 assertNever ,
22+ getChildProcessErrorMessage ,
2223 getErrorMessage ,
2324 getErrorStack ,
2425} from "../common/helpers-pure" ;
@@ -1643,7 +1644,7 @@ export async function runCodeQlCliCommand(
16431644 return result . stdout ;
16441645 } catch ( err ) {
16451646 throw new Error (
1646- `${ description } failed: ${ ( err as any ) . stderr || getErrorMessage ( err ) } ` ,
1647+ `${ description } failed: ${ getChildProcessErrorMessage ( err ) } ` ,
16471648 ) ;
16481649 }
16491650}
Original file line number Diff line number Diff line change @@ -67,3 +67,26 @@ export function asError(e: unknown): Error {
6767
6868 return e instanceof Error ? e : new Error ( String ( e ) ) ;
6969}
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+ }
You can’t perform that action at this time.
0 commit comments