error.js
This file
Path
lib/error.js
108 lines · 2.8 KiB · JavaScript
Last changed by
Fix `timeout` option (#727)ehmickybefore adoptiona61a028
History of this fileTake it
The walk stopped after 200 commits: lines older than 408904b point at 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';Improve `error.message` (#705)ehmickybefore adoption67b476b
line 3why, one step back3import stripFinalNewline from 'strip-final-newline';Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 4why, one step back4import {isBinary, binaryToString} from './stdio/utils.js';Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 5–29why, one step back56const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => {7 if (timedOut) {8 return `timed out after ${timeout} milliseconds`;9 }1011 if (isCanceled) {12 return 'was canceled';13 }1415 if (errorCode !== undefined) {16 return `failed with ${errorCode}`;17 }1819 if (signal !== undefined) {20 return `was killed with ${signal} (${signalDescription})`;21 }2223 if (exitCode !== undefined) {24 return `failed with exit code ${exitCode}`;25 }2627 return 'failed';28};29Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 30–36why, one step back30const serializeMessagePart = messagePart => Array.isArray(messagePart)31 ? messagePart.map(messageItem => serializeMessageItem(messageItem)).join('')32 : serializeMessageItem(messagePart);3334const serializeMessageItem = messageItem => {35 if (typeof messageItem === 'string') {36 return messageItem;Improve `error.message` (#705)ehmickybefore adoption67b476b
line 37why, one step back37 }Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55
line 38why, one step back38Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
lines 39–40why, one step back39 if (isBinary(messageItem)) {40 return binaryToString(messageItem);Improve `error.message` (#705)ehmickybefore adoption67b476b
lines 41–45why, one step back41 }4243 return '';44};45Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 46why, one step back46export const makeError = ({Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 47why, one step back47 stdio,Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 48–52why, one step back48 all,49 error,50 signal,51 exitCode,52 command,Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 53why, one step back53 escapedCommand,Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 54–55why, one step back54 timedOut,55 isCanceled,Fix `timeout` option (#727)ehmickybefore adoptiona61a028
line 56why, one step back56 options: {timeoutDuration: timeout, cwd = process.cwd()},Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 57–67why, one step back57}) => {58 // `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.59 // We normalize them to `undefined`60 exitCode = exitCode === null ? undefined : exitCode;61 signal = signal === null ? undefined : signal;62 const signalDescription = signal === undefined ? undefined : signalsByName[signal].description;6364 const errorCode = error && error.code;6566 const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});67 const execaMessage = `Command ${prefix}: ${command}`;Fix checking for `Error` instances (#423)ehmickybefore adoptiond37f927
lines 68–69why, one step back68 const isError = Object.prototype.toString.call(error) === '[object Error]';69 const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;Improve `error.message` (#705)ehmickybefore adoption67b476b
lines 70–72why, one step back70 const messageStdio = all === undefined ? [stdio[2], stdio[1]] : [all];71 const message = [shortMessage, ...messageStdio, ...stdio.slice(3)]72 .map(messagePart => stripFinalNewline(serializeMessagePart(messagePart)))Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55
line 73why, one step back73 .filter(Boolean)Improve `error.message` (#705)ehmickybefore adoption67b476b
line 74why, one step back74 .join('\n\n');Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
line 75why, one step back75Fix checking for `Error` instances (#423)ehmickybefore adoptiond37f927
line 76why, one step back76 if (isError) {Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 77–84why, one step back77 error.originalMessage = error.message;78 error.message = message;79 } else {80 error = new Error(message);81 }8283 error.shortMessage = shortMessage;84 error.command = command;Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 85why, one step back85 error.escapedCommand = escapedCommand;Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 86–88why, one step back86 error.exitCode = exitCode;87 error.signal = signal;88 error.signalDescription = signalDescription;Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 89–91why, one step back89 error.stdio = stdio;90 error.stdout = stdio[1];91 error.stderr = stdio[2];Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
line 92why, one step back92 error.cwd = cwd;Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 93–104why, one step back9394 if (all !== undefined) {95 error.all = all;96 }9798 if ('bufferedData' in error) {99 delete error.bufferedData;100 }101102 error.failed = true;103 error.timedOut = Boolean(timedOut);104 error.isCanceled = isCanceled;Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 105why, one step back105 error.isTerminated = signal !== undefined;Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 106–108why, one step back106107 return error;108};