Skip to content
Myr

throw.js

This file

Path

lib/pipe/throw.js

58 lines · 1.5 KiB · JavaScript

Last changed by

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

History of this file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

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

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 3why, one step back
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.

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 6–10why, one step back
6export const handlePipeArgumentsError = ({
7 sourceStream,8 sourceError,9 destinationStream,10 destinationError,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 11why, one step back
11 fileDescriptors,

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 12why, one step back
12 sourceOptions,

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

line 13why, one step back
13 startTime,

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 14why, one step back
14}) => {

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 15–20why, one step back
15 const error = getPipeArgumentsError({
16 sourceStream,17 sourceError,18 destinationStream,19 destinationError,20 });

Improve `.pipe()` method (#859)ehmickybefore adoption2ef9e86

line 21why, one step back
21 if (error !== undefined) {

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 22–27why, one step back
22 throw createNonCommandError({
23 error,24 fileDescriptors,25 sourceOptions,26 startTime,27 });

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 28–46why, one step back
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 }4041 if (sourceError !== undefined) {42 endDestinationStream(destinationStream);43 return sourceError;44 }45};46

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

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

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 48why, one step back
48export const createNonCommandError = ({error, fileDescriptors, sourceOptions, startTime}) => makeEarlyError({

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 49–51why, one step back
49 error,
50 command: PIPE_COMMAND_MESSAGE,51 escapedCommand: PIPE_COMMAND_MESSAGE,

Refactor `stdio` option (#927)ehmickybefore adoptionc9cdd2d

line 52why, one step back
52 fileDescriptors,

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

line 53why, one step back
53 options: sourceOptions,

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

line 54why, one step back
54 startTime,

Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815

line 55why, one step back
55 isSync: false,

Fix errors thrown by `.pipe()` (#854)ehmickybefore adoption46ba4b4

lines 56–58why, one step back
56});
5758const PIPE_COMMAND_MESSAGE = 'source.pipe(destination)';