From 24e90c5330973b0d6c4713983fc2cc6ab564ed2a Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 3 Mar 2021 18:44:08 +0100 Subject: [PATCH] Product more useful error output when a non-array is produced --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 988af8b..ddf8038 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ const Promise = require("bluebird"); const propagateAbort = require("@promistream/propagate-abort"); const unreachable = require("@joepie91/unreachable")("@promistream/buffer"); +const util = require("util"); module.exports = function bufferStream() { let buffer; @@ -20,7 +21,11 @@ module.exports = function bufferStream() { return attemptRead(readFunc); } } else { - throw new Error("Buffered stream produced a non-array value"); + // FIXME: Make this its own module, and improve its compactness? + let stringified = util.inspect(result, { depth: 0 }) + .replace(/\s+/g, " "); + + throw new Error(`Buffered stream produced a non-array value: ${stringified}`); } }); }