Skip to content
Myr

Do not set `undefined` properties on the return value (#992)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent c78ae5c · Browse files · 3 files+60 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+60 added−33 removed

  • tests:+0 added−3 removed
  • other:+60 added−30 removed

3 files+60 added−33 removed

modified:lib/methods/template.js+1 added-1 removed
modified:lib/return/result.js+59 added-29 removed
9 unmodified lines
10 stdio,11 all,12 options: {cwd},13 startTime,14}) => ({14}) => omitUndefinedProperties({15 command,16 escapedCommand,17 cwd,18 durationMs: getDurationMs(startTime),
64 unmodified lines
83 timeout,84 cwd,85 });86 const error = getFinalError(originalError, message, isSync);8788 error.shortMessage = shortMessage;89 error.originalMessage = originalMessage;90 error.command = command;91 error.escapedCommand = escapedCommand;92 error.cwd = cwd;93 error.durationMs = getDurationMs(startTime);9495 error.failed = true;96 error.timedOut = timedOut;97 error.isCanceled = isCanceled;98 error.isTerminated = signal !== undefined;99 error.isMaxBuffer = isMaxBuffer;100 error.exitCode = exitCode;101 error.signal = signal;102 error.signalDescription = signalDescription;103 error.code = error.cause?.code;104105 error.stdout = stdio[1];106 error.stderr = stdio[2];107108 if (all !== undefined) {109 error.all = all;110 }111112 error.stdio = stdio;113 error.pipedFrom = [];11487 Object.assign(error, getErrorProperties({88 error,89 command,90 escapedCommand,91 startTime,92 timedOut,93 isCanceled,94 isMaxBuffer,95 exitCode,96 signal,97 signalDescription,98 stdio,99 all,100 cwd,101 originalMessage,102 shortMessage,103 }));104 return error;105};106107const getErrorProperties = ({108 error,109 command,110 escapedCommand,111 startTime,112 timedOut,113 isCanceled,114 isMaxBuffer,115 exitCode,116 signal,117 signalDescription,118 stdio,119 all,120 cwd,121 originalMessage,122 shortMessage,123}) => omitUndefinedProperties({124 shortMessage,125 originalMessage,126 command,127 escapedCommand,128 cwd,129 durationMs: getDurationMs(startTime),130 failed: true,131 timedOut,132 isCanceled,133 isTerminated: signal !== undefined,134 isMaxBuffer,135 exitCode,136 signal,137 signalDescription,138 code: error.cause?.code,139 stdout: stdio[1],140 stderr: stdio[2],141 all,142 stdio,143 pipedFrom: [],144});145146const omitUndefinedProperties = result => Object.fromEntries(Object.entries(result).filter(([, value]) => value !== undefined));147148// `signal` and `exitCode` emitted on `subprocess.on('exit')` event can be `null`.149// We normalize them to `undefined`150const normalizeExitPayload = (rawExitCode, rawSignal) => {151 const exitCode = rawExitCode === null ? undefined : rawExitCode;
4 unmodified lines
modified:test/return/result.js-3 removed
48 unmodified lines
49 'isCanceled',50 'isTerminated',51 'isMaxBuffer',52 'exitCode',53 'signal',54 'signalDescription',55 'code',53 'stdout',54 'stderr',55 'all',56 'stdio',
86 unmodified lines