Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add KillSignal.prototype.abortedExitCode #220

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ function validateCommandName(command: string) {
const SHELL_SIGNAL_CTOR_SYMBOL = Symbol();

interface KillSignalState {
abortedCode: number;
abortedCode: number | undefined;
listeners: ((signal: Deno.Signal) => void)[];
}

Expand All @@ -1086,7 +1086,7 @@ export class KillSignalController {

constructor() {
this.#state = {
abortedCode: 0,
abortedCode: undefined,
listeners: [],
};
this.#killSignal = new KillSignal(SHELL_SIGNAL_CTOR_SYMBOL, this.#state);
Expand Down Expand Up @@ -1131,7 +1131,12 @@ export class KillSignal {
* SIGKILL, SIGABRT, SIGQUIT, SIGINT, or SIGSTOP
*/
get aborted(): boolean {
return this.#state.abortedCode !== 0;
return this.#state.abortedCode !== undefined;
}

/** Gets the exit code to use if aborted. */
get abortedExitCode(): number | undefined {
return this.#state.abortedCode;
}

/**
Expand Down Expand Up @@ -1160,11 +1165,6 @@ export class KillSignal {
this.#state.listeners.splice(index, 1);
}
}

/** @internal - DO NOT USE. Very unstable. Not sure about this. */
get _abortedExitCode() {
return this.#state.abortedCode;
}
}

function sendSignalToState(state: KillSignalState, signal: Deno.Signal) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function executeCat(context: CommandContext) {
if (!size || size === 0) break;
else context.stdout.writeSync(buf.slice(0, size));
}
exitCode = context.signal._abortedExitCode;
exitCode = context.signal.abortedExitCode ?? 0;
} else {
const _assertValue: "null" | "inherit" = context.stdin;
throw new Error(`not supported. stdin was '${context.stdin}'`);
Expand All @@ -47,7 +47,7 @@ async function executeCat(context: CommandContext) {
if (!size || size === 0) break;
else context.stdout.writeSync(buf.slice(0, size));
}
exitCode = context.signal._abortedExitCode;
exitCode = context.signal.abortedExitCode ?? 0;
} catch (err) {
context.stderr.writeLine(`cat ${path}: ${err}`);
exitCode = 1;
Expand Down
Loading