Skip to content

Commit

Permalink
fix: throw a well-typed error on run failure (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 authored May 30, 2024
1 parent 3762df2 commit d848cc0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### TBA

- Throw a typed `TestRunFailedError` on failure instead of a string.

### 2.4.0 | 2024-05-24

- Allow installing unreleased builds using an `-unreleased` suffix, such as `insiders-unreleased`.
Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

export { download, downloadAndUnzipVSCode, DownloadOptions } from './download';
export { runTests, TestOptions } from './runTest';
export { runTests, TestOptions, TestRunFailedError } from './runTest';
export {
resolveCliPathFromVSCodeExecutablePath,
resolveCliArgsFromVSCodeExecutablePath,
Expand Down
15 changes: 9 additions & 6 deletions lib/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,10 @@ async function innerRunTests(
cmd.stdout.destroy();
cmd.stderr.destroy();

if (code === null) {
reject(signal);
} else if (code !== 0) {
reject('Failed');
if (code !== 0) {
reject(new TestRunFailedError(code ?? undefined, signal ?? undefined));
} else {
console.log('Done\n');
resolve(code ?? -1);
resolve(0);
}
}

Expand All @@ -190,3 +187,9 @@ async function innerRunTests(

return code;
}

export class TestRunFailedError extends Error {
constructor(public readonly code: number | undefined, public readonly signal: string | undefined) {
super(signal ? `Test run terminated with signal ${signal}` : `Test run failed with code ${code}`);
}
}

0 comments on commit d848cc0

Please sign in to comment.