Skip to content
Myr

Add `cwd` error property (#565)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by homersimpsons · committed by GitHub · parent a228eda · Browse files · 5 files+34 added−4 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+34 added−4 removed

  • tests:+12 added−1 removed
  • other:+22 added−3 removed

5 files+34 added−4 removed

modified:lib/error.js+3 added-1 removed
modified:test/error.js+12 added-1 removed
1 unmodified line
2import childProcess from 'node:child_process';3import {promisify} from 'node:util';4import test from 'ava';5import {execa, execaSync} from '../index.js';6import {setFixtureDir} from './helpers/fixtures-dir.js';6import {FIXTURES_DIR, setFixtureDir} from './helpers/fixtures-dir.js';78const pExec = promisify(childProcess.exec);910setFixtureDir();
200 unmodified lines
211test('error.code is defined on failure if applicable', async t => {212 const {code} = await t.throwsAsync(execa('noop.js', {cwd: 1}));213 t.is(code, 'ERR_INVALID_ARG_TYPE');214});215216test('error.cwd is defined on failure if applicable', async t => {217 const {cwd} = await t.throwsAsync(execa('noop-throw.js', [], {cwd: FIXTURES_DIR}));218 t.is(cwd, FIXTURES_DIR);219});220221test('error.cwd is undefined on failure if not passed as options', async t => {222 const expectedCwd = process.cwd();223 const {cwd} = await t.throwsAsync(execa('noop-throw.js'));224 t.is(cwd, expectedCwd);225});
modified:index.d.ts+9 added-2 removed
362 unmodified lines
363364 If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.365 */366 signalDescription?: string;367368 /**369 The `cwd` of the command if provided in the command options. Otherwise it is `process.cwd()`.370 */371 cwd: string;372};373374export type ExecaSyncReturnValue<StdoutStderrType extends StdoutStderrAll = string> = {375} & ExecaReturnBase<StdoutStderrType>;
224 unmodified lines
600 stderr: '',601 failed: true,602 timedOut: false,603 isCanceled: false,599 killed: false604 killed: false,605 cwd: '/path/to/cwd'606 }607 \*\/608}609```
74 unmodified lines
684 stderr: '',685 failed: true,686 timedOut: false,687 isCanceled: false,682 killed: false688 killed: false,689 cwd: '/path/to/cwd'690 }691 \*\/692}693```
244 unmodified lines
modified:index.test-d.ts+4 added
69 unmodified lines
70 expectType<boolean>(unicornsResult.isCanceled);71 expectType<boolean>(unicornsResult.killed);72 expectType<string | undefined>(unicornsResult.signal);73 expectType<string | undefined>(unicornsResult.signalDescription);74 expectType<string>(unicornsResult.cwd);75} catch (error: unknown) {76 const execaError = error as ExecaError;7778 expectType<string>(execaError.message);
6 unmodified lines
85 expectType<boolean>(execaError.isCanceled);86 expectType<boolean>(execaError.killed);87 expectType<string | undefined>(execaError.signal);88 expectType<string | undefined>(execaError.signalDescription);89 expectType<string>(execaError.cwd);90 expectType<string>(execaError.shortMessage);91 expectType<string | undefined>(execaError.originalMessage);92}93
13 unmodified lines
107 expectError(unicornsResult.isCanceled);108 expectType<boolean>(unicornsResult.killed);109 expectType<string | undefined>(unicornsResult.signal);110 expectType<string | undefined>(unicornsResult.signalDescription);111 expectType<string>(unicornsResult.cwd);112} catch (error: unknown) {113 const execaError = error as ExecaSyncError;114115 expectType<string>(execaError.message);
6 unmodified lines
122 expectError(execaError.isCanceled);123 expectType<boolean>(execaError.killed);124 expectType<string | undefined>(execaError.signal);125 expectType<string | undefined>(execaError.signalDescription);126 expectType<string>(execaError.cwd);127 expectType<string>(execaError.shortMessage);128 expectType<string | undefined>(execaError.originalMessage);129}130
190 unmodified lines
modified:readme.md+6 added
459 unmodified lines
460A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`.461462If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.463464#### cwd465466Type: `string`467468The `cwd` of the command if provided in the [command options](#cwd-1). Otherwise it is `process.cwd()`.469470#### message471472Type: `string`473
351 unmodified lines