Add getChildProcessErrorMessage
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
} from "./distribution";
|
||||
import {
|
||||
assertNever,
|
||||
getChildProcessErrorMessage,
|
||||
getErrorMessage,
|
||||
getErrorStack,
|
||||
} from "../common/helpers-pure";
|
||||
@@ -1643,7 +1644,7 @@ export async function runCodeQlCliCommand(
|
||||
return result.stdout;
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`${description} failed: ${(err as any).stderr || getErrorMessage(err)}`,
|
||||
`${description} failed: ${getChildProcessErrorMessage(err)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,3 +67,26 @@ export function asError(e: unknown): Error {
|
||||
|
||||
return e instanceof Error ? e : new Error(String(e));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error message when the error may have come from a method from the `child_process` module.
|
||||
*/
|
||||
export function getChildProcessErrorMessage(e: unknown): string {
|
||||
return isChildProcessError(e) ? e.stderr : getErrorMessage(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error thrown from methods from the `child_process` module.
|
||||
*/
|
||||
interface ChildProcessError {
|
||||
readonly stderr: string;
|
||||
}
|
||||
|
||||
function isChildProcessError(e: unknown): e is ChildProcessError {
|
||||
return (
|
||||
typeof e === "object" &&
|
||||
e !== null &&
|
||||
"stderr" in e &&
|
||||
typeof e.stderr === "string"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user