From 3bcdcbcd081b5c1809085ce49a6a737c7461de98 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 3 Mar 2021 11:39:14 +0100 Subject: [PATCH] Detect non-streams and improve error reporting --- index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 72ff0b5..2f2412f 100644 --- a/index.js +++ b/index.js @@ -16,13 +16,17 @@ module.exports = function pipe(streams) { function getPipeline(source) { if (!boundPipelineCache.has(source)) { - let pipeline = existentStreams.reduce((bound, stream) => { - if (stream.read == null) { - throw new Error(`Stream is missing a read handler (stream description: ${stream.description})`); + let pipeline = existentStreams.reduce((bound, stream, i) => { + // TODO: Use Validatem for this instead + // FIXME: Stream index is currently wrong if there were any nulls in the streams list, correct for this + if (!(typeof stream === "object") || Array.isArray(stream)) { + throw new Error(`Value at index ${i} in the pipeline is not a stream`); + } else if (stream.read == null) { + throw new Error(`Stream at index ${i} is missing a read handler (stream description: ${stream.description})`); } else if (stream.abort == null) { - throw new Error(`Stream is missing an abort handler (stream description: ${stream.description})`); + throw new Error(`Stream at index ${i} is missing an abort handler (stream description: ${stream.description})`); } else if (stream.peek == null) { - throw new Error(`Stream is missing a peek handler (stream description: ${stream.description})`); + throw new Error(`Stream at index ${i} is missing a peek handler (stream description: ${stream.description})`); } else { if (bound != null) { return Object.assign({}, stream, {