Add `error.originalMessage` property (#373)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by Sindre Sorhus · parent 492dff4 · Browse files · 5 files·+23 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+23 added−0 removed
- tests:+5 added−0 removed
- other:+18 added−0 removed
Provenance
- Commit
07d2b76- Tree
c30a583- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
492dff4
5 files changed+23 added−0 removed
modified:lib/error.js+1 added
51 unmodified lines52535455565758596028 unmodified lines51 unmodified lines const prefix = getErrorPrefix({timedOut, timeout, signal, exitCodeName, exitCode, isCanceled}); const message = `Command ${prefix}: ${command}`;
if (error instanceof Error) { error.originalMessage = error.message; error.message = `${message}\n${error.message}`; } else { error = new Error(message); }28 unmodified linesmodified:test/error.js+5 added
161 unmodified lines162 errorMessage.title = (message, expected) => `error.message matches: ${expected}`;163 164 test(errorMessage, /Command failed with exit code 2.*: exit 2 foo bar/, 2, 'foo', 'bar');165 test(errorMessage, /Command failed with exit code 3.*: exit 3 baz quz/, 3, 'baz', 'quz');166+167+test('Original error message is kept', async t => {168+ const {originalMessage} = await t.throwsAsync(execa('wrong command'));169+ t.is(originalMessage, 'spawn wrong command ENOENT');170+});modified:index.d.ts+7 added
300 unmodified lines301 /**302 The error message.303 */304 message: string;305+306+ /**307+ Original error message. This is `undefined` unless the child process exited due to an `error` event or a timeout.308+309+ The `message` property contains both the `originalMessage` and some additional information added by Execa.310+ */311+ originalMessage?: string;312 }313 314 interface ExecaError<StdoutErrorType = string>315 extends ExecaSyncError<StdoutErrorType> {190 unmodified linesmodified:index.test-d.ts+2 added
38 unmodified lines39 expectType<boolean>(execaError.timedOut);40 expectType<boolean>(execaError.isCanceled);41 expectType<boolean>(execaError.killed);42 expectType<string | undefined>(execaError.signal);43+ expectType<string | undefined>(execaError.originalMessage);44 }45 46 try {47 const unicornsResult = execa.sync('unicorns');21 unmodified lines69 expectType<boolean>(execaError.timedOut);70 expectError(execaError.isCanceled);71 expectType<boolean>(execaError.killed);72 expectType<string | undefined>(execaError.signal);73+ expectType<string | undefined>(execaError.originalMessage);74 }75 76 execa('unicorns', {cleanup: false});77 execa('unicorns', {preferLocal: false});109 unmodified linesmodified:readme.md+8 added
275 unmodified lines276 Type: `string | undefined`277 278 The signal that was used to terminate the process.279 280+#### originalMessage281+282+Type: `string | undefined`283+284+Original error message. This is `undefined` unless the child process exited due to an `error` event or a timeout.285+286+The `message` property contains both the `originalMessage` and some additional information added by Execa.287+288 ### options289 290 Type: `object`291 268 unmodified lines