error.js
This file
Path
lib/error.js
94 lines · 2.4 KiB · JavaScript
Last changed by
Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55
History of this fileTake it
The walk stopped after 200 commits: lines older than e003f9c 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';Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55
line 3why, one step back3import {isUint8Array} from './stdio/utils.js';3.2.0ehmickybefore adoptione003f9c
lines 4–28why, one step back45const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => {6 if (timedOut) {7 return `timed out after ${timeout} milliseconds`;8 }910 if (isCanceled) {11 return 'was canceled';12 }1314 if (errorCode !== undefined) {15 return `failed with ${errorCode}`;16 }1718 if (signal !== undefined) {19 return `was killed with ${signal} (${signalDescription})`;20 }2122 if (exitCode !== undefined) {23 return `failed with exit code ${exitCode}`;24 }2526 return 'failed';27};28Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55
lines 29–32why, one step back29const serializeMessagePart = messagePart => isUint8Array(messagePart)30 ? new TextDecoder().decode(messagePart)31 : messagePart;32Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 33why, one step back33export const makeError = ({Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
line 34why, one step back34 stdio,3.2.0ehmickybefore adoptione003f9c
lines 35–39why, one step back35 all,36 error,37 signal,38 exitCode,39 command,Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 40why, one step back40 escapedCommand,3.2.0ehmickybefore adoptione003f9c
lines 41–42why, one step back41 timedOut,42 isCanceled,Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0
line 43why, one step back43 options: {timeout, cwd = process.cwd()},3.2.0ehmickybefore adoptione003f9c
lines 44–53why, one step back44}) => {45 // `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.46 // We normalize them to `undefined`47 exitCode = exitCode === null ? undefined : exitCode;48 signal = signal === null ? undefined : signal;49 const signalDescription = signal === undefined ? undefined : signalsByName[signal].description;5051 const errorCode = error && error.code;5253 const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 54why, one step back54 const execaMessage = `Command ${prefix}: ${command}`;Fix checking for `Error` instances (#423)ehmickybefore adoptiond37f927
lines 55–56why, one step back55 const isError = Object.prototype.toString.call(error) === '[object Error]';56 const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55
lines 57–60why, one step back57 const message = [shortMessage, stdio[2], stdio[1], ...stdio.slice(3)]58 .filter(Boolean)59 .map(messagePart => serializeMessagePart(messagePart))60 .join('\n');3.2.0ehmickybefore adoptione003f9c
line 61why, one step back61Fix checking for `Error` instances (#423)ehmickybefore adoptiond37f927
line 62why, one step back62 if (isError) {3.2.0ehmickybefore adoptione003f9c
line 63why, one step back63 error.originalMessage = error.message;Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 64why, one step back64 error.message = message;3.2.0ehmickybefore adoptione003f9c
lines 65–68why, one step back65 } else {66 error = new Error(message);67 }68Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9
line 69why, one step back69 error.shortMessage = shortMessage;3.2.0ehmickybefore adoptione003f9c
line 70why, one step back70 error.command = command;Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 71why, one step back71 error.escapedCommand = escapedCommand;3.2.0ehmickybefore adoptione003f9c
lines 72–74why, one step back72 error.exitCode = exitCode;73 error.signal = signal;74 error.signalDescription = signalDescription;Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207
lines 75–77why, one step back75 error.stdio = stdio;76 error.stdout = stdio[1];77 error.stderr = stdio[2];Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec
line 78why, one step back78 error.cwd = cwd;3.2.0ehmickybefore adoptione003f9c
lines 79–90why, one step back7980 if (all !== undefined) {81 error.all = all;82 }8384 if ('bufferedData' in error) {85 delete error.bufferedData;86 }8788 error.failed = true;89 error.timedOut = Boolean(timedOut);90 error.isCanceled = isCanceled;Fix `error.killed` and rename to `error.isTerminated` (#625)ehmickybefore adoption248349c
line 91why, one step back91 error.isTerminated = signal !== undefined;3.2.0ehmickybefore adoptione003f9c
lines 92–94why, one step back9293 return error;94};