Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Stop burying stderr output within exec
Browse files Browse the repository at this point in the history
The exec util buries stderr output. This makes it difficult to understand why your script is failing.

Example: Here's how it currently works. Notice there is nothing specific about what went wrong in the error output:

```sh
npm run storybook:publish -- --bucket-path=XXXXXXXXXXXXXX

=> Building storybook for: web
   executing: build-storybook  -o out8599
=> Deploying storybook
   executing: aws --profile default s3 sync out8599 s3://XXXXXXXXXXXXXX

/Users/dandean/Code/splice/web/node_modules/@storybook/storybook-deployer/src/utils.js:19
  throw new Error(
  ^

Error: Exec code(255) on executing: aws --profile default s3 sync out8599 s3://XXXXXXXXXXXXXX
undefined
```

Result: Here's what happens with this patch:

```sh
npm run storybook:publish -- --bucket-path=XXXXXXXXXXXXXX

=> Building storybook for: web
   executing: build-storybook  -o out8599
=> Deploying storybook
   executing: aws --profile default s3 sync out8599 s3://XXXXXXXXXXXXXX

The config profile (default) could not be found

/Users/dandean/Code/splice/web/node_modules/@storybook/storybook-deployer/src/utils.js:19
  throw new Error(
  ^

Error: Exec code(255) on executing: aws --profile default s3 sync out8599 s3://XXXXXXXXXXXXXX
undefined
```

We can now see the source of the error as indicated by the command which we executed:

> The config profile (default) could not be found
  • Loading branch information
dandean authored Jan 30, 2020
1 parent 6aacf53 commit edaa0ec
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ module.exports.exec = function exec(command) {
if (ref.code === 0) {
return ref.stdout.trim();
}

// If the failed shell exec has meaningful error output, do not bury it:
if (ref.stderr.trim()) {
console.error(ref.stderr);
}

throw new Error(
`Exec code(${ref.code}) on executing: ${command}\n${shell.stderr}`
Expand Down

0 comments on commit edaa0ec

Please sign in to comment.