Skip to content
Myr

throw.js

This file

Path

lib/pipe/throw.js

60 lines · 1.5 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 1–40why, one step back
1import {makeEarlyError} from '../return/result.js';
2import {abortSourceStream, endDestinationStream} from '../io/pipeline.js';34// When passing invalid arguments to `source.pipe()`, throw asynchronously.5// We also abort both subprocesses.6export const handlePipeArgumentsError = ({7 sourceStream,8 sourceError,9 destinationStream,10 destinationError,11 fileDescriptors,12 sourceOptions,13 startTime,14}) => {15 const error = getPipeArgumentsError({16 sourceStream,17 sourceError,18 destinationStream,19 destinationError,20 });21 if (error !== undefined) {22 throw createNonCommandError({23 error,24 fileDescriptors,25 sourceOptions,26 startTime,27 });28 }29};3031const getPipeArgumentsError = ({sourceStream, sourceError, destinationStream, destinationError}) => {32 if (sourceError !== undefined && destinationError !== undefined) {33 return destinationError;34 }3536 if (destinationError !== undefined) {37 abortSourceStream(sourceStream);38 return destinationError;39 }40

TweaksSindre Sorhusbefore adoption698a1b8

lines 41–42why, one step back
41 if (sourceError === undefined) {
42 return;

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 43why, one step back
43 }

TweaksSindre Sorhusbefore adoption698a1b8

lines 44–46why, one step back
44
45 endDestinationStream(destinationStream);46 return sourceError;

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 47–60why, one step back
47};
4849// Specific error return value when passing invalid arguments to `subprocess.pipe()` or when using `unpipeSignal`50export const createNonCommandError = ({error, fileDescriptors, sourceOptions, startTime}) => makeEarlyError({51 error,52 command: PIPE_COMMAND_MESSAGE,53 escapedCommand: PIPE_COMMAND_MESSAGE,54 fileDescriptors,55 options: sourceOptions,56 startTime,57 isSync: false,58});5960const PIPE_COMMAND_MESSAGE = 'source.pipe(destination)';