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 fileTake it
Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
line 1why, one step back1import {inspect} from 'node:util';Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
line 2why, one step back2import stripFinalNewline from 'strip-final-newline';Rename files (#977)ehmickybefore adoption4b2e316
line 3why, one step back3import {isUint8Array, uint8ArrayToString} from '../utils/uint-array.js';Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 4–5why, one step back4import {fixCwdError} from '../arguments/cwd.js';5import {escapeLines} from '../arguments/escape.js';Rename files (#977)ehmickybefore adoption4b2e316
line 6why, one step back6import {getMaxBufferMessage} from '../io/max-buffer.js';Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 7why, one step back7import {getSignalDescription} from '../terminate/signal.js';Rename files (#977)ehmickybefore adoption4b2e316
line 8why, one step back8import {DiscardedError, isExecaError} from './final-error.js';Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
line 9why, one step back9Add more code comments (#984)ehmickybefore adoptionfdd8a9f
line 10why, one step back10// Computes `error.message`, `error.shortMessage` and `error.originalMessage`Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 11–13why, one step back11export const createMessages = ({12 stdio,13 all,Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
line 14why, one step back14 ipcOutput,Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 15–21why, one step back15 originalError,16 signal,17 signalDescription,18 exitCode,19 escapedCommand,20 timedOut,21 isCanceled,Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 22why, one step back22 isGracefullyCanceled,Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
line 23why, one step back23 isMaxBuffer,Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
lines 24–26why, one step back24 isForcefullyTerminated,25 forceKillAfterDelay,26 killSignal,Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 27–31why, one step back27 maxBuffer,28 timeout,29 cwd,30}) => {31 const errorCode = originalError?.code;Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 32–42why, one step back32 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 back43 isGracefullyCanceled,Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
lines 44–46why, one step back44 isForcefullyTerminated,45 forceKillAfterDelay,46 killSignal,Upgrade xo (#980)ehmickybefore adoptionccfa412
line 47why, one step back47 });Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
line 48why, one step back48 const originalMessage = getOriginalMessage(originalError, cwd);Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c
lines 49–50why, one step back49 const suffix = originalMessage === undefined ? '' : `\n${originalMessage}`;50 const shortMessage = `${prefix}: ${escapedCommand}${suffix}`;Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
line 51why, one step back51 const messageStdio = all === undefined ? [stdio[2], stdio[1]] : [all];Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
lines 52–55why, one step back52 const message = [53 shortMessage,54 ...messageStdio,55 ...stdio.slice(3),Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
line 56why, one step back56 ipcOutput.map(ipcMessage => serializeIpcMessage(ipcMessage)).join('\n'),Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
line 57why, one step back57 ]Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 58–63why, one step back58 .map(messagePart => escapeLines(stripFinalNewline(serializeMessagePart(messagePart))))59 .filter(Boolean)60 .join('\n\n');61 return {originalMessage, shortMessage, message};62};63Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
lines 64–74why, one step back64const 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 back75 isGracefullyCanceled,Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
lines 76–81why, one step back76 isForcefullyTerminated,77 forceKillAfterDelay,78 killSignal,79}) => {80 const forcefulSuffix = getForcefulSuffix(isForcefullyTerminated, forceKillAfterDelay);81Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
line 82why, one step back82 if (timedOut) {Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 83why, one step back83 return `Command timed out after ${timeout} milliseconds${forcefulSuffix}`;Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
lines 84–93why, one step back84 }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 back94 }9596 if (isCanceled) {Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 97why, one step back97 return `Command was canceled${forcefulSuffix}`;Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 98–100why, one step back98 }99100 if (isMaxBuffer) {Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 101why, one step back101 return `${getMaxBufferMessage(originalError, maxBuffer)}${forcefulSuffix}`;Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 102–104why, one step back102 }103104 if (errorCode !== undefined) {Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
line 105why, one step back105 return `Command failed with ${errorCode}${forcefulSuffix}`;Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 106–107why, one step back106 }107Add `error.isForcefullyTerminated` (#1111)ehmickybefore adoptione69985d
lines 108–111why, one step back108 if (isForcefullyTerminated) {109 return `Command was killed with ${killSignal} (${getSignalDescription(killSignal)})${forcefulSuffix}`;110 }111Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 112–121why, one step back112 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 back122123const 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 back126127const getOriginalMessage = (originalError, cwd) => {128 if (originalError instanceof DiscardedError) {Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c
line 129why, one step back129 return;Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 130–134why, one step back130 }131132 const originalMessage = isExecaError(originalError)133 ? originalError.originalMessage134 : String(originalError?.message ?? originalError);Fix `error.originalMessage` (#991)ehmickybefore adoptionc78ae5c
lines 135–136why, one step back135 const escapedOriginalMessage = escapeLines(fixCwdError(originalMessage, cwd));136 return escapedOriginalMessage === '' ? undefined : escapedOriginalMessage;Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
line 137why, one step back137};Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de
lines 138–141why, one step back138139const serializeIpcMessage = ipcMessage => typeof ipcMessage === 'string'140 ? ipcMessage141 : inspect(ipcMessage);Split files into smaller ones (#976)ehmickybefore adoptiond7c6853
lines 142–157why, one step back142143const 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};