Skip to content

Commit 11f1c8e

Browse files
refactor(cli): improve error handling for remote script fetch (#1408)
1 parent 857c401 commit 11f1c8e

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

build/cli.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ function readScriptFromHttp(remote) {
325325
const res = yield (0, import_index.fetch)(remote);
326326
if (!res.ok) {
327327
console.error(`Error: Can't get ${remote}`);
328-
import_node_process2.default.exit(1);
328+
import_node_process2.default.exitCode = 1;
329+
throw new import_index.Fail(`Failed to fetch remote script: ${remote} (${res.status})`);
329330
}
330331
return res.text();
331332
});

src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ async function readScriptFromHttp(remote: string): Promise<string> {
252252
const res = await fetch(remote)
253253
if (!res.ok) {
254254
console.error(`Error: Can't get ${remote}`)
255-
process.exit(1)
255+
process.exitCode = 1
256+
throw new Fail(`Failed to fetch remote script: ${remote} (${res.status})`)
256257
}
257258
return res.text()
258259
}

test/cli.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ console.log(a);
285285
const server = await fakeServer([`HTTP/1.1 500\n\n500\n`]).listen(port)
286286
const out = await $`node build/cli.js http://127.0.0.1:${port}`.nothrow()
287287
assert.match(out.stderr, /Error: Can't get/)
288+
assert.match(out.stderr, /Failed to fetch remote script/)
289+
assert.equal(out.exitCode, 1)
288290
await server.stop()
289291
})
290292

0 commit comments

Comments
 (0)