error.js
This file
Path
lib/error.js
114 lines · 3.1 KiB · JavaScript
Last changed by
Improve `cwd` option (#803)ehmickybefore adoption2fd9351
History of this fileTake it
The walk stopped after 200 commits: lines older than fd3c7be point at it.
Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 1why, one step back1import {signalsByName} from 'human-signals';Improve `error.message` (#705)ehmickybefore adoption67b476b
line 2why, one step back2import stripFinalNewline from 'strip-final-newline';Allow any type with transforms (#709)ehmickybefore adoptioned8b2ce
line 3why, one step back3import {isBinary, binaryToString} from './stdio/utils.js';Improve `cwd` option (#803)ehmickybefore adoption2fd9351
line 4why, one step back4import {fixCwdError} from './cwd.js';Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
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,Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
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,Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
lines 54–55why, one step back54 timedOut,55 isCanceled,Improve `cwd` option (#803)ehmickybefore adoption2fd9351
line 56why, one step back56 options: {timeoutDuration: timeout, cwd},Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
lines 57–63why, 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;63Fix return value being re-used between multiple calls (#796)ehmickybefore adoption7710440
line 64why, one step back64 const errorCode = error?.code;Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
lines 65–66why, one step back65 const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});66 const execaMessage = `Command ${prefix}: ${command}`;Improve `cwd` option (#803)ehmickybefore adoption2fd9351
lines 67–68why, one step back67 const originalErrorMessage = previousErrors.has(error) ? error.originalMessage : String(error?.message ?? error);68 const originalMessage = fixCwdError(originalErrorMessage, cwd);Fix return value being re-used between multiple calls (#796)ehmickybefore adoption7710440
line 69why, one step back69 const shortMessage = error === undefined ? execaMessage : `${execaMessage}\n${originalMessage}`;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');Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
line 75why, one step back75Fix return value being re-used between multiple calls (#796)ehmickybefore adoption7710440
line 76why, one step back76 if (Object.prototype.toString.call(error) !== '[object Error]' || previousErrors.has(error)) {Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
line 77why, one step back77 error = new Error(message);Fix return value being re-used between multiple calls (#796)ehmickybefore adoption7710440
lines 78–82why, one step back78 error.originalMessage = originalMessage;79 } else {80 previousErrors.add(error);81 error.message = message;82 error.originalMessage = originalMessage;Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
lines 83–86why, one step back83 }8485 error.shortMessage = shortMessage;86 error.command = command;Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 87why, one step back87 error.escapedCommand = escapedCommand;Re-order return value properties (#801)ehmickybefore adoption72836f3
lines 88–93why, one step back88 error.cwd = cwd;8990 error.failed = true;91 error.timedOut = Boolean(timedOut);92 error.isCanceled = isCanceled;93 error.isTerminated = signal !== undefined;Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
lines 94–96why, one step back94 error.exitCode = exitCode;95 error.signal = signal;96 error.signalDescription = signalDescription;Re-order return value properties (#801)ehmickybefore adoption72836f3
line 97why, one step back97Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 98–99why, one step back98 error.stdout = stdio[1];99 error.stderr = stdio[2];Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
lines 100–104why, one step back100101 if (all !== undefined) {102 error.all = all;103 }104Re-order return value properties (#801)ehmickybefore adoption72836f3
lines 105–106why, one step back105 error.stdio = stdio;106Rename `master` branch to `main`Sindre Sorhusbefore adoptionfd3c7be
lines 107–112why, one step back107 if ('bufferedData' in error) {108 delete error.bufferedData;109 }110111 return error;112};Fix return value being re-used between multiple calls (#796)ehmickybefore adoption7710440
lines 113–114why, one step back113114const previousErrors = new WeakSet();