From 40b8b72610b49b5d2f7622bef2938aef1fdd9d84 Mon Sep 17 00:00:00 2001 From: Gilad Goldberg Date: Mon, 16 May 2016 17:56:33 +0300 Subject: [PATCH] feat(error): Show a more descriptive error when the script was not found (#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. --- .all-contributorsrc | 7 +++++++ README.md | 6 +++--- src/index.js | 2 +- src/index.test.js | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5b8cbea..c6d4701 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -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": [] } ] } \ No newline at end of file diff --git a/README.md b/README.md index b4dd80e..f0ba2f7 100644 --- a/README.md +++ b/README.md @@ -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 @@ -238,8 +238,8 @@ benefits of npm scripts I wanted to keep). Thanks goes to these people ([emoji key][emojis]): -| [![Kent C. Dodds](https://avatars.githubusercontent.com/u/1500684?v=3&s=100)
Kent C. Dodds](http://kent.doddsfamily.us)
[💻](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)
David Wells](http://davidwells.io)
[💻](https://github.com/kentcdodds/p-s/commits?author=DavidWells) | [![Abhishek Shende](https://avatars.githubusercontent.com/u/802242?v=3&s=100)
Abhishek Shende](https://twitter.com/abhishekisnot)
[💻](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)
Rowan Oulton](http://travelog.io)
[💻](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) | -| :---: | :---: | :---: | :---: | +| [
Kent C. Dodds](http://kent.doddsfamily.us)
[💻](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) 🚇 💡 | [
David Wells](http://davidwells.io)
[💻](https://github.com/kentcdodds/p-s/commits?author=DavidWells) | [
Abhishek Shende](https://twitter.com/abhishekisnot)
[💻](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) [⚠️](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) | [
Rowan Oulton](http://travelog.io)
[💻](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) | [
Gilad Goldberg](https://github.com/giladgo)
| +| :---: | :---: | :---: | :---: | :---: | This project follows the [all-contributors][all-contributors] specification. diff --git a/src/index.js b/src/index.js index 4bf0f2b..4f75af4 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { diff --git a/src/index.test.js b/src/index.test.js index 88e838f..75126ee 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -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()