Skip to content

Commit

Permalink
Fix missing exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Nov 3, 2023
1 parent 333c8ce commit d4be77f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-buttons-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"every-ts": patch
---

Fix missing exit codes
16 changes: 11 additions & 5 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ export class ExitError extends Error {
}

export abstract class BaseCommand extends Command {
override catch(error: any): Promise<void> {
if (error instanceof ExitError) {
this.context.stderr.write(`${error.message}\n`);
return Promise.resolve<any>(error.exitCode);
override async execute(): Promise<number | void> {
try {
return await this.executeOrThrow();
} catch (e) {
if (e instanceof ExitError) {
this.context.stderr.write(`${e.message}\n`);
return e.exitCode;
}
throw e;
}
return super.catch(error);
}

abstract executeOrThrow(): Promise<number | void>;
}

export async function revParse(rev: string) {
Expand Down
8 changes: 4 additions & 4 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Bisect extends BaseCommand {
subcommand = Option.String({ required: true });
args = Option.Proxy();

override async execute(): Promise<number | void> {
override async executeOrThrow(): Promise<number | void> {
let startArgs: string[] = [];
let revs;
let endArgs: string[] = [];
Expand Down Expand Up @@ -117,7 +117,7 @@ export class BisectRun extends BaseCommand {

args = Option.Proxy({ required: 1 });

override async execute(): Promise<number | void> {
override async executeOrThrow(): Promise<number | void> {
await ensureRepo();

if (!await getBisectInfo()) {
Expand Down Expand Up @@ -168,7 +168,7 @@ export class Switch extends BaseCommand {

rev = Option.String({ required: false });

override async execute(): Promise<number | void> {
override async executeOrThrow(): Promise<number | void> {
await ensureRepo();

const target = await findRev(this.rev ?? `main`, true);
Expand Down Expand Up @@ -200,7 +200,7 @@ export class Fetch extends BaseCommand {
description: `Fetches the latest info for the TypeScript checkout.`,
});

override async execute(): Promise<number | void> {
override async executeOrThrow(): Promise<number | void> {
await ensureRepo();
await execa(`git`, [`fetch`, `--all`, `--tags`], { cwd: tsDir });
// This will usually be a noop, but if this is what's used to fetch the first time,
Expand Down
8 changes: 4 additions & 4 deletions src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Tsc extends BaseCommand {

args = Option.Proxy();

override async execute(): Promise<number | void> {
override async executeOrThrow(): Promise<number | void> {
await ensureBuilt();
const { tsc } = getPaths();
const result = await execa(`node`, [tsc, ...this.args], { stdio: `inherit`, reject: false });
Expand All @@ -30,7 +30,7 @@ export class Tsdk extends BaseCommand {

args = Option.Proxy();

override async execute(): Promise<number | void> {
override async executeOrThrow(): Promise<number | void> {
await ensureBuilt();
const { baseDir } = getPaths();
console.log(`"typescript.tsdk": ${JSON.stringify(baseDir)}`);
Expand All @@ -46,7 +46,7 @@ export class Exec extends BaseCommand {

args = Option.Proxy({ required: 1 });

override async execute(): Promise<number | void> {
override async executeOrThrow(): Promise<number | void> {
await ensureBuilt();
const result = await execa(
this.args[0],
Expand All @@ -64,7 +64,7 @@ export class Dir extends BaseCommand {
description: `Gets the path to the TypeScript checkout, for use in "npm link", etc.`,
});

override async execute(): Promise<number | void> {
override async executeOrThrow(): Promise<number | void> {
await ensureBuilt();
console.log(tsDir);
}
Expand Down

0 comments on commit d4be77f

Please sign in to comment.