From a1f41ecfb7db462fa262c58e80431c61e9434e4f Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 19 Sep 2023 01:09:30 +0200 Subject: [PATCH] fix: attach stdout/stderr to error object --- src/index.js | 2 +- test/error.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 2c25457..e59f264 100644 --- a/src/index.js +++ b/src/index.js @@ -12,7 +12,7 @@ const isJSON = (str = '') => str.startsWith('{') const parse = ({ stdout, stderr, ...details }) => { if (stdout !== '' && stdout !== 'null') return isJSON(stdout) ? JSON.parse(stdout) : stdout - throw Object.assign(new Error(stderr), details) + throw Object.assign(new Error(stderr), { stderr, stdout }, details) } const create = binaryPath => { diff --git a/test/error.js b/test/error.js index c586d34..1ae2621 100644 --- a/test/error.js +++ b/test/error.js @@ -9,7 +9,7 @@ test('show help', async t => { }) test('unsupported URLs', async t => { - t.plan(4) + t.plan(6) const url = 'https://www.apple.com/homepod' try { await youtubedl(url, { dumpSingleJson: true, noWarnings: true }) @@ -20,6 +20,8 @@ test('unsupported URLs', async t => { ) t.true(error instanceof Error) t.truthy(error.command) + t.truthy(error.stderr) + t.truthy(error.stdout) t.truthy(error.exitCode) } })