Skip to content

Commit a23261b

Browse files
authored
feat: pass origin error as ProcessOuput cause (#1110)
1 parent b571839 commit a23261b

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

.size-limit.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "zx/core",
44
"path": ["build/core.cjs", "build/util.cjs", "build/vendor-core.cjs"],
5-
"limit": "77.5 kB",
5+
"limit": "77.6 kB",
66
"brotli": false,
77
"gzip": false
88
},
@@ -30,7 +30,7 @@
3030
{
3131
"name": "all",
3232
"path": "build/*",
33-
"limit": "850 kB",
33+
"limit": "850.2 kB",
3434
"brotli": false,
3535
"gzip": false
3636
}

src/core.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@ type ProcessDto = {
675675

676676
export class ProcessOutput extends Error {
677677
private readonly _dto: ProcessDto
678+
cause!: Error | null
679+
message!: string
680+
stdout!: string
681+
stderr!: string
682+
stdall!: string
678683
constructor(dto: ProcessDto)
679684
constructor(
680685
code: number | null,
@@ -704,6 +709,7 @@ export class ProcessOutput extends Error {
704709
: { code, signal, duration, error, from, store }
705710

706711
Object.defineProperties(this, {
712+
cause: { value: dto.error, enumerable: false, writable: true, configurable: true },
707713
stdout: { get: once(() => bufArrJoin(dto.store.stdout)) },
708714
stderr: { get: once(() => bufArrJoin(dto.store.stderr)) },
709715
stdall: { get: once(() => bufArrJoin(dto.store.stdall)) },
@@ -715,10 +721,6 @@ export class ProcessOutput extends Error {
715721
},
716722
})
717723
}
718-
message!: string
719-
stdout!: string
720-
stderr!: string
721-
stdall!: string
722724

723725
get exitCode(): number | null {
724726
return this._dto.code

src/goods.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export async function spinner<T>(
194194
title: string | (() => T),
195195
callback?: () => T
196196
): Promise<T> {
197-
if (typeof title == 'function') {
197+
if (typeof title === 'function') {
198198
callback = title
199199
title = ''
200200
}

test/core.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,17 @@ describe('core', () => {
253253
assert.equal(o1.exitCode, 1)
254254
assert.match(o1.message, /exit code: 1/)
255255

256+
const err = new Error('BrokenSpawn')
256257
const o2 = await $({
257258
nothrow: true,
258259
spawn() {
259-
throw new Error('BrokenSpawn')
260+
throw err
260261
},
261262
})`echo foo`
262263
assert.equal(o2.ok, false)
263264
assert.equal(o2.exitCode, null)
264265
assert.match(o2.message, /BrokenSpawn/)
266+
assert.equal(o2.cause, err)
265267
})
266268

267269
test('handles `input` option', async () => {

0 commit comments

Comments
 (0)