Skip to content
Myr

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 file

Take 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 back
1import process from 'node:process';

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 2why, one step back
2import {signalsByName} from 'human-signals';

Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55

line 3why, one step back
3import {isUint8Array} from './stdio/utils.js';

3.2.0ehmickybefore adoptione003f9c

lines 4–28why, one step back
4
5const 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};28

Fix `error.message` when using `encoding: 'buffer'` (#701)ehmickybefore adoptionb8c1f55

lines 29–32why, one step back
29const serializeMessagePart = messagePart => isUint8Array(messagePart)
30 ? new TextDecoder().decode(messagePart)31 : messagePart;32

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 33why, one step back
33export const makeError = ({

Add `result.stdio` and `error.stdio` (#676)ehmickybefore adoption62a5207

line 34why, one step back
34 stdio,

3.2.0ehmickybefore adoptione003f9c

lines 35–39why, one step back
35 all,
36 error,37 signal,38 exitCode,39 command,

Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc

line 40why, one step back
40 escapedCommand,

3.2.0ehmickybefore adoptione003f9c

lines 41–42why, one step back
41 timedOut,
42 isCanceled,

Refactor duplicate code between `execa()` and `execaSync()` (#648)ehmickybefore adoption4fb84f0

line 43why, one step back
43 options: {timeout, cwd = process.cwd()},

3.2.0ehmickybefore adoptione003f9c

lines 44–53why, one step back
44}) => {
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 back
54 const execaMessage = `Command ${prefix}: ${command}`;

Fix checking for `Error` instances (#423)ehmickybefore adoptiond37f927

lines 55–56why, one step back
55 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 back
57 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 back
61

Fix checking for `Error` instances (#423)ehmickybefore adoptiond37f927

line 62why, one step back
62 if (isError) {

3.2.0ehmickybefore adoptione003f9c

line 63why, one step back
63 error.originalMessage = error.message;

Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9

line 64why, one step back
64 error.message = message;

3.2.0ehmickybefore adoptione003f9c

lines 65–68why, one step back
65 } else {
66 error = new Error(message);67 }68

Add stdout/stderr to error messages (#397)ehmickybefore adoptionbc520f9

line 69why, one step back
69 error.shortMessage = shortMessage;

3.2.0ehmickybefore adoptione003f9c

line 70why, one step back
70 error.command = command;

Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc

line 71why, one step back
71 error.escapedCommand = escapedCommand;

3.2.0ehmickybefore adoptione003f9c

lines 72–74why, one step back
72 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 back
75 error.stdio = stdio;
76 error.stdout = stdio[1];77 error.stderr = stdio[2];

Add `cwd` error property (#565)homersimpsonsbefore adoptionf57fdec

line 78why, one step back
78 error.cwd = cwd;

3.2.0ehmickybefore adoptione003f9c

lines 79–90why, one step back
79
80 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 back
91 error.isTerminated = signal !== undefined;

3.2.0ehmickybefore adoptione003f9c

lines 92–94why, one step back
92
93 return error;94};