Skip to content

Commit

Permalink
fix: attach stdout/stderr to error object
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 18, 2023
1 parent 9b29329 commit a1f41ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
4 changes: 3 additions & 1 deletion test/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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)
}
})
Expand Down

0 comments on commit a1f41ec

Please sign in to comment.