error.js
This file
Path
lib/error.js
87 lines · 2.2 KiB · JavaScript
Last changed by
Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
History of this fileTake it
Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
line 1why, one step back1import process from 'node:process';Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 2why, one step back2import {signalsByName} from 'human-signals';Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
lines 3–4why, one step back34const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => {Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 5–12why, one step back5 if (timedOut) {6 return `timed out after ${timeout} milliseconds`;7 }89 if (isCanceled) {10 return 'was canceled';11 }12Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 13–17why, one step back13 if (errorCode !== undefined) {14 return `failed with ${errorCode}`;15 }1617 if (signal !== undefined) {Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
line 18why, one step back18 return `was killed with ${signal} (${signalDescription})`;Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 19–21why, one step back19 }2021 if (exitCode !== undefined) {Fix error properties (#375)ehmickybefore adoptionc1b511b
line 22why, one step back22 return `failed with exit code ${exitCode}`;Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 23–27why, one step back23 }2425 return 'failed';26};27Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 28why, one step back28export const makeError = ({Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 29–33why, one step back29 stdout,30 stderr,31 all,32 error,33 signal,Fix error properties (#375)ehmickybefore adoptionc1b511b
line 34why, one step back34 exitCode,Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 35why, one step back35 command,Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 36why, one step back36 escapedCommand,Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 37–39why, one step back37 timedOut,38 isCanceled,39 killed,Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
line 40why, one step back40 parsed: {options: {timeout, cwd = process.cwd()}},Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 41why, one step back41}) => {Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 42–45why, one step back42 // `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.43 // We normalize them to `undefined`44 exitCode = exitCode === null ? undefined : exitCode;45 signal = signal === null ? undefined : signal;Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
line 46why, one step back46 const signalDescription = signal === undefined ? undefined : signalsByName[signal].description;Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 47why, one step back47Fix error properties (#375)ehmickybefore adoptionc1b511b
lines 48–49why, one step back48 const errorCode = error && error.code;49Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
line 50why, one step back50 const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 51why, one step back51 const execaMessage = `Command ${prefix}: ${command}`;Fix checking for `Error` instances (#423)ehmickybefore adoptiond37f927
lines 52–53why, one step back52 const isError = Object.prototype.toString.call(error) === '[object Error]';53 const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 54why, one step back54 const message = [shortMessage, stderr, stdout].filter(Boolean).join('\n');Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 55why, one step back55Fix checking for `Error` instances (#423)ehmickybefore adoptiond37f927
line 56why, one step back56 if (isError) {Add `error.originalMessage` property (#373)ehmickybefore adoption07d2b76
line 57why, one step back57 error.originalMessage = error.message;Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 58why, one step back58 error.message = message;Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 59–62why, one step back59 } else {60 error = new Error(message);61 }62Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 63why, one step back63 error.shortMessage = shortMessage;Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 64why, one step back64 error.command = command;Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 65why, one step back65 error.escapedCommand = escapedCommand;Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
line 66why, one step back66 error.exitCode = exitCode;Fix error properties (#375)ehmickybefore adoptionc1b511b
line 67why, one step back67 error.signal = signal;Add `error.signalDescription` (#378)ehmickybefore adoptiond8cb08f
line 68why, one step back68 error.signalDescription = signalDescription;Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 69–70why, one step back69 error.stdout = stdout;70 error.stderr = stderr;Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
line 71why, one step back71 error.cwd = cwd;Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 72–81why, one step back7273 if (all !== undefined) {74 error.all = all;75 }7677 if ('bufferedData' in error) {78 delete error.bufferedData;79 }8081 error.failed = true;Refactor the `timeout` option (#333)ehmickybefore adoption2a7551f
line 82why, one step back82 error.timedOut = Boolean(timedOut);Separate error creation logic into its own file (#311)ehmickybefore adoption4dd258d
lines 83–87why, one step back83 error.isCanceled = isCanceled;84 error.killed = killed && !timedOut;8586 return error;87};