Skip to content
Myr

message.js

This file

Path

lib/return/message.js

157 lines · 4.1 KiB · JavaScript

Last changed by

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

History of this file

Take it

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

line 1why, one step back
1import {inspect} from 'node:util';

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

line 2why, one step back
2import stripFinalNewline from 'strip-final-newline';

Rename files (#977)ehmickybefore adoption4b2e316

line 3why, one step back
3import {isUint8Array, uint8ArrayToString} from '../utils/uint-array.js';

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 4–5why, one step back
4import {fixCwdError} from '../arguments/cwd.js';
5import {escapeLines} from '../arguments/escape.js';

Rename files (#977)ehmickybefore adoption4b2e316

line 6why, one step back
6import {getMaxBufferMessage} from '../io/max-buffer.js';

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

line 7why, one step back
7import {getSignalDescription} from '../terminate/signal.js';

Rename files (#977)ehmickybefore adoption4b2e316

line 8why, one step back
8import {DiscardedError, isExecaError} from './final-error.js';

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

line 9why, one step back
9

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 10why, one step back
10// Computes `error.message`, `error.shortMessage` and `error.originalMessage`

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 11–13why, one step back
11export const createMessages = ({
12 stdio,13 all,

Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360

line 14why, one step back
14 ipcOutput,

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 15–21why, one step back
15 originalError,
16 signal,17 signalDescription,18 exitCode,19 escapedCommand,20 timedOut,21 isCanceled,

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 22why, one step back
22 isGracefullyCanceled,

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

line 23why, one step back
23 isMaxBuffer,

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

lines 24–26why, one step back
24 isForcefullyTerminated,
25 forceKillAfterDelay,26 killSignal,

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 27–31why, one step back
27 maxBuffer,
28 timeout,29 cwd,30}) => {31 const errorCode = originalError?.code;

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 32–42why, one step back
32 const prefix = getErrorPrefix({
33 originalError,34 timedOut,35 timeout,36 isMaxBuffer,37 maxBuffer,38 errorCode,39 signal,40 signalDescription,41 exitCode,42 isCanceled,

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 43why, one step back
43 isGracefullyCanceled,

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

lines 44–46why, one step back
44 isForcefullyTerminated,
45 forceKillAfterDelay,46 killSignal,

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 47why, one step back
47 });

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

line 48why, one step back
48 const originalMessage = getOriginalMessage(originalError, cwd);

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 49–50why, one step back
49 const suffix = originalMessage === undefined ? '' : `\n${originalMessage}`;
50 const shortMessage = `${prefix}: ${escapedCommand}${suffix}`;

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

line 51why, one step back
51 const messageStdio = all === undefined ? [stdio[2], stdio[1]] : [all];

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

lines 52–55why, one step back
52 const message = [
53 shortMessage,54 ...messageStdio,55 ...stdio.slice(3),

Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360

line 56why, one step back
56 ipcOutput.map(ipcMessage => serializeIpcMessage(ipcMessage)).join('\n'),

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

line 57why, one step back
57 ]

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 58–63why, one step back
58 .map(messagePart => escapeLines(stripFinalNewline(serializeMessagePart(messagePart))))
59 .filter(Boolean)60 .join('\n\n');61 return {originalMessage, shortMessage, message};62};63

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

lines 64–74why, one step back
64const getErrorPrefix = ({
65 originalError,66 timedOut,67 timeout,68 isMaxBuffer,69 maxBuffer,70 errorCode,71 signal,72 signalDescription,73 exitCode,74 isCanceled,

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 75why, one step back
75 isGracefullyCanceled,

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

lines 76–81why, one step back
76 isForcefullyTerminated,
77 forceKillAfterDelay,78 killSignal,79}) => {80 const forcefulSuffix = getForcefulSuffix(isForcefullyTerminated, forceKillAfterDelay);81

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

line 82why, one step back
82 if (timedOut) {

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

line 83why, one step back
83 return `Command timed out after ${timeout} milliseconds${forcefulSuffix}`;

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

lines 84–93why, one step back
84 }
8586 if (isGracefullyCanceled) {87 if (signal === undefined) {88 return `Command was gracefully canceled with exit code ${exitCode}`;89 }9091 return isForcefullyTerminated92 ? `Command was gracefully canceled${forcefulSuffix}`93 : `Command was gracefully canceled with ${signal} (${signalDescription})`;

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 94–96why, one step back
94 }
9596 if (isCanceled) {

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

line 97why, one step back
97 return `Command was canceled${forcefulSuffix}`;

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 98–100why, one step back
98 }
99100 if (isMaxBuffer) {

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

line 101why, one step back
101 return `${getMaxBufferMessage(originalError, maxBuffer)}${forcefulSuffix}`;

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 102–104why, one step back
102 }
103104 if (errorCode !== undefined) {

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

line 105why, one step back
105 return `Command failed with ${errorCode}${forcefulSuffix}`;

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 106–107why, one step back
106 }
107

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

lines 108–111why, one step back
108 if (isForcefullyTerminated) {
109 return `Command was killed with ${killSignal} (${getSignalDescription(killSignal)})${forcefulSuffix}`;110 }111

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 112–121why, one step back
112 if (signal !== undefined) {
113 return `Command was killed with ${signal} (${signalDescription})`;114 }115116 if (exitCode !== undefined) {117 return `Command failed with exit code ${exitCode}`;118 }119120 return 'Command failed';121};

Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d

lines 122–125why, one step back
122
123const getForcefulSuffix = (isForcefullyTerminated, forceKillAfterDelay) => isForcefullyTerminated124 ? ` and was forcefully terminated after ${forceKillAfterDelay} milliseconds`125 : '';

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 126–128why, one step back
126
127const getOriginalMessage = (originalError, cwd) => {128 if (originalError instanceof DiscardedError) {

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

line 129why, one step back
129 return;

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 130–134why, one step back
130 }
131132 const originalMessage = isExecaError(originalError)133 ? originalError.originalMessage134 : String(originalError?.message ?? originalError);

Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c

lines 135–136why, one step back
135 const escapedOriginalMessage = escapeLines(fixCwdError(originalMessage, cwd));
136 return escapedOriginalMessage === '' ? undefined : escapedOriginalMessage;

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

line 137why, one step back
137};

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

lines 138–141why, one step back
138
139const serializeIpcMessage = ipcMessage => typeof ipcMessage === 'string'140 ? ipcMessage141 : inspect(ipcMessage);

Split files into smaller ones (#976)ehmickybefore adoptiond7c6853

lines 142–157why, one step back
142
143const serializeMessagePart = messagePart => Array.isArray(messagePart)144 ? messagePart.map(messageItem => stripFinalNewline(serializeMessageItem(messageItem))).filter(Boolean).join('\n')145 : serializeMessageItem(messagePart);146147const serializeMessageItem = messageItem => {148 if (typeof messageItem === 'string') {149 return messageItem;150 }151152 if (isUint8Array(messageItem)) {153 return uint8ArrayToString(messageItem);154 }155156 return '';157};