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 08eb743 point at it.

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 1–3why, one step back
1import {makeEarlyError} from '../return/result.js';
2import {abortSourceStream, endDestinationStream} from '../io/pipeline.js';3

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

lines 4–5why, one step back
4// When passing invalid arguments to `source.pipe()`, throw asynchronously.
5// We also abort both subprocesses.

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 6–40why, one step back
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;

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

line 43why, one step back
43 }

TweaksSindre Sorhusbefore adoption698a1b8

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

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 47–48why, one step back
47};
48

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 49why, one step back
49// Specific error return value when passing invalid arguments to `subprocess.pipe()` or when using `unpipeSignal`

Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743

lines 50–60why, one step back
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)';