| 1 | // When the subprocess fails, this is the error instance being returned. |
| 2 | // If another error instance is being thrown, it is kept as `error.cause`. |
| 3 | export const getFinalError = (originalError, message, isSync) => { |
| 4 | const ErrorClass = isSync ? ExecaSyncError : ExecaError; |
| 5 | const options = originalError instanceof DiscardedError ? {} : {cause: originalError}; |
| 6 | return new ErrorClass(message, options); |
| 7 | }; |
| 8 | |
| 9 | // Indicates that the error is used only to interrupt control flow, but not in the return value |
| 10 | export class DiscardedError extends Error {} |