Skip to content

Commit

Permalink
feat(error): Show a more descriptive error when the script was not fo…
Browse files Browse the repository at this point in the history
…und (#7)

Until now, the error message displayed was kind of short and uninformative. This PR makes the error
message more informative by displaying the name of the script that was not found.
  • Loading branch information
giladgo authored and Kent C. Dodds committed May 16, 2016
1 parent 9c94f76 commit 40b8b72
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
"doc",
"test"
]
},
{
"login": "giladgo",
"name": "Gilad Goldberg",
"avatar_url": "https://avatars.githubusercontent.com/u/1915716?v=3",
"profile": "https://github.com/giladgo",
"contributions": []
}
]
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ All the benefits of npm scripts without the cost of a bloated package.json and l
[![MIT License][license-badge]][LICENSE]
[![PRs Welcome][prs-badge]](http://makeapullrequest.com)
[![Donate][donate-badge]][donate]
[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors)

## The problem

Expand Down Expand Up @@ -238,8 +238,8 @@ benefits of npm scripts I wanted to keep).
Thanks goes to these people ([emoji key][emojis]):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [![Kent C. Dodds](https://avatars.githubusercontent.com/u/1500684?v=3&s=100)<br /><sub>Kent C. Dodds</sub>](http://kent.doddsfamily.us)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) 🚇 💡 | [![David Wells](https://avatars.githubusercontent.com/u/532272?v=3&s=100)<br /><sub>David Wells</sub>](http://davidwells.io)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=DavidWells) | [![Abhishek Shende](https://avatars.githubusercontent.com/u/802242?v=3&s=100)<br /><sub>Abhishek Shende</sub>](https://twitter.com/abhishekisnot)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) [⚠️](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) | [![Rowan Oulton](https://avatars.githubusercontent.com/u/185649?v=3&s=100)<br /><sub>Rowan Oulton</sub>](http://travelog.io)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [📖](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [⚠️](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) |
| :---: | :---: | :---: | :---: |
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](http://kent.doddsfamily.us)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) 🚇 💡 | [<img src="https://avatars.githubusercontent.com/u/532272?v=3" width="100px;"/><br /><sub>David Wells</sub>](http://davidwells.io)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=DavidWells) | [<img src="https://avatars.githubusercontent.com/u/802242?v=3" width="100px;"/><br /><sub>Abhishek Shende</sub>](https://twitter.com/abhishekisnot)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) [⚠️](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) | [<img src="https://avatars.githubusercontent.com/u/185649?v=3" width="100px;"/><br /><sub>Rowan Oulton</sub>](http://travelog.io)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [📖](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [⚠️](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) | [<img src="https://avatars.githubusercontent.com/u/1915716?v=3" width="100px;"/><br /><sub>Gilad Goldberg</sub>](https://github.com/giladgo)<br /> |
| :---: | :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors][all-contributors] specification.
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function runPackageScript({scriptConfig, options = {}, scriptName, args}) {
const scripts = getScriptsFromConfig(scriptConfig, scriptName)
const script = getScriptToRun(scripts, scriptName)
if (!isString(script)) {
return new Error('scripts must resolve to strings')
return new Error('Scripts must resolve to strings. Is there a script named \'' + scriptName + '\'?')
}
const command = [script, args].join(' ').trim()
if (!options.silent) {
Expand Down
3 changes: 2 additions & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ test.cb('throws when the script is not a string', t => {
rewireDeps()
const scriptConfig = {lint: {script: 42}}
runPackageScript({scriptConfig, scripts: ['lint']}, ({error}) => {
if (!error || !(error instanceof Error) || error.message !== 'scripts must resolve to strings') {
if (!error || !(error instanceof Error) ||
error.message !== 'Scripts must resolve to strings. Is there a script named \'lint\'?') {
t.end('Error is not the expected error: ' + JSON.stringify(error))
}
t.end()
Expand Down

0 comments on commit 40b8b72

Please sign in to comment.