Skip to content

Commit 7b82043

Browse files
evangraykfacebook-github-bot
authored andcommitted
Distinguish EjecaSpawnError from EjecaError
Summary: There's two error types from Ejeca: 1. a command spawns then exits non-zero 2. a command does not spawn (syscall to spawn fails) (1) is what we typically think of as an EjecaError, and contains most normal errors. (2) can happen with ENOENT if `sl` or other commands like `gh` are not on your PATH. The distinction is important for good error messages. Let's make them separate types to keep these separate. Reviewed By: quark-zju Differential Revision: D67995419 fbshipit-source-id: ee8df2d40929277280f564b36ac07e9a1a56c336
1 parent 7540058 commit 7b82043

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

addons/isl-server/src/github/queryGraphQL.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import {Internal} from '../Internal';
9-
import {isEjecaError} from '../utils';
9+
import {isEjecaError, isEjecaSpawnError} from '../utils';
1010
import {ejeca} from 'shared/ejeca';
1111

1212
export default async function queryGraphQL<TData, TVariables>(
@@ -52,12 +52,14 @@ export default async function queryGraphQL<TData, TVariables>(
5252

5353
return json.data;
5454
} catch (error: unknown) {
55-
if (isEjecaError(error)) {
56-
// FIXME: we're never setting `code` in ejeca, so this is always false!
55+
if (isEjecaSpawnError(error)) {
5756
if (error.code === 'ENOENT' || error.code === 'EACCES') {
5857
// `gh` not installed on path
5958
throw new Error(`GhNotInstalledError: ${(error as Error).stack}`);
60-
} else if (error.exitCode === 4) {
59+
}
60+
} else if (isEjecaError(error)) {
61+
// FIXME: we're never setting `code` in ejeca, so this is always false!
62+
if (error.exitCode === 4) {
6163
// `gh` CLI exit code 4 => authentication issue
6264
throw new Error(`NotAuthenticatedError: ${(error as Error).stack}`);
6365
}

addons/isl-server/src/utils.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,22 @@ export function parseExecJson<T>(
164164
});
165165
}
166166

167-
// FIXME: we're not ever setting `code`!
168-
export function isEjecaError(s: unknown): s is EjecaError & {code?: string} {
167+
export type EjecaSpawnError = Error & {code: string; path: string};
168+
169+
/**
170+
* True if an Ejeca spawned process exits non-zero or is killed.
171+
* @see {EjecaSpawnError} for when a process fails to spawn in the first place (e.g. ENOENT).
172+
*/
173+
export function isEjecaError(s: unknown): s is EjecaError {
169174
return s != null && typeof s === 'object' && 'exitCode' in s;
170175
}
171176

177+
/** True when Ejeca fails to spawn a process, e.g. ENOENT.
178+
* (as opposed to the command spawning, then exiting non-zero) */
179+
export function isEjecaSpawnError(s: unknown): s is EjecaSpawnError {
180+
return s != null && typeof s === 'object' && 'code' in s;
181+
}
182+
172183
export function fromEntries<V>(entries: Array<[string, V]>): {
173184
[key: string]: V;
174185
} {

0 commit comments

Comments
 (0)