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
Provenance
- Commit
0d33b6d- Tree
3716cdd- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
c78ae5c
3 files changed+60 added−33 removed
modified:lib/methods/template.js+1 added-1 removed
118 unmodified linesExpand all11912012112212312312412512612722 unmodified lines118 unmodified linesExpand all if (typeOfExpression === 'number') { return String(expression); }
if (isPlainObject(expression) && 'stdout' in expression) { if (isPlainObject(expression) && ('stdout' in expression || 'isMaxBuffer' in expression)) { return getSubprocessResult(expression); }
if (expression instanceof ChildProcess || Object.prototype.toString.call(expression) === '[object Promise]') {22 unmodified linesmodified:lib/return/result.js+59 added-29 removed
9 unmodified lines10 stdio,11 all,12 options: {cwd},13 startTime,14-}) => ({14+}) => omitUndefinedProperties({15 command,16 escapedCommand,17 cwd,18 durationMs: getDurationMs(startTime),64 unmodified lines83 timeout,84 cwd,85 });86 const error = getFinalError(originalError, message, isSync);87-88- error.shortMessage = shortMessage;89- error.originalMessage = originalMessage;90- error.command = command;91- error.escapedCommand = escapedCommand;92- error.cwd = cwd;93- error.durationMs = getDurationMs(startTime);94-95- 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;104-105- error.stdout = stdio[1];106- error.stderr = stdio[2];107-108- if (all !== undefined) {109- error.all = all;110- }111-112- error.stdio = stdio;113- error.pipedFrom = [];114-87+ 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 };106 107+const 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+});145+146+const omitUndefinedProperties = result => Object.fromEntries(Object.entries(result).filter(([, value]) => value !== undefined));147+148 // `signal` and `exitCode` emitted on `subprocess.on('exit')` event can be `null`.149 // We normalize them to `undefined`150 const normalizeExitPayload = (rawExitCode, rawSignal) => {151 const exitCode = rawExitCode === null ? undefined : rawExitCode;4 unmodified linesmodified:test/return/result.js-3 removed
48 unmodified lines49 'isCanceled',50 'isTerminated',51 'isMaxBuffer',52 'exitCode',53- 'signal',54- 'signalDescription',55- 'code',53 'stdout',54 'stderr',55 'all',56 'stdio',86 unmodified lines