Skip to content

Commit

Permalink
feat: display a meaningful error when the config file is missing (#288)
Browse files Browse the repository at this point in the history
* feat: display a meaningful error when the config file is missing

## What

When you try to add a user with `.all-contributorsrc` missing, you will get a cryptic error message (see also all-contributors/all-contributors#378):

```
$ all-contributors add darekkay maintenance
Cannot read property 'then' of null
```

This PR displays a meaningful error message in this case.

## Why

So users know what's causing the problem.

## How

Before a contribution is being added, the script checks whether the config file exists. If it doesn't, an error message is being displayed:

```
$ all-contributors add darekkay maintenance
Configuration file not found: C:\projects\test\.all-contributorsrc
```

* docs: add darekkay as a contributor

* refactor: fixed typos

* docs(readme): table rectification

Co-authored-by: Maximilian Berkmann <maxieberkmann@gmail.com>
  • Loading branch information
darekkay and Berkmann18 committed Oct 4, 2020
1 parent 24004d5 commit d517440
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,15 @@
"code",
"test"
]
},
{
"login": "darekkay",
"name": "Darek Kay",
"avatar_url": "https://avatars0.githubusercontent.com/u/3101914?v=4",
"profile": "https://darekkay.com/",
"contributions": [
"code"
]
}
],
"skipCi": true
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ Thanks goes to these wonderful people
<td align="center"><a href="https://www.linkedin.com/in/mloning/"><img src="https://avatars3.githubusercontent.com/u/21020482?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Markus Löning</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=mloning" title="Code">💻</a></td>
<td align="center"><a href="https://dlaa.me/"><img src="https://avatars1.githubusercontent.com/u/1828270?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David Anson</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/issues?q=author%3ADavidAnson" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=Favna" title="Code">💻</a></td>
<td align="center"><a href="https://erekspeed.com"><img src="https://avatars3.githubusercontent.com/u/1176550?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Erek Speed</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=melink14" title="Code">💻</a></td>
<td align="center"><a href="http://www.hirez.io"><img src="https://avatars1.githubusercontent.com/u/1430726?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Shai Reznik</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/issues?q=author%3Ashairez" title="Bug reports">🐛</a> <a href="https://github.com/all-contributors/all-contributors-cli/commits?author=shairez" title="Code">💻</a> <a href="https://github.com/all-contributors/all-contributors-cli/commits?author=shairez" title="Tests">⚠️</a></td>
<td align="center"><a href="https://darekkay.com/"><img src="https://avatars0.githubusercontent.com/u/3101914?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Darek Kay</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=darekkay" title="Code">💻</a></td>
<td align="center"><a href="https://erekspeed.com"><img src="https://avatars3.githubusercontent.com/u/1176550?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Erek Speed</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=melink14" title="Code">💻</a></td>
</tr>
</table>

Expand Down
1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function startGeneration(argv) {
}

function addContribution(argv) {
util.configFile.readConfig(argv.config) // ensure the config file exists
const username = argv._[1] === undefined ? undefined : String(argv._[1])
const contributions = argv._[2]
// Add or update contributor in the config file
Expand Down
2 changes: 1 addition & 1 deletion src/generate/__tests__/format-contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test('format contributor with pipes in their name', () => {
expect(formatContributor(options, contributor)).toBe(expected)
})

test('format contributor with no github account', () => {
test('format contributor with no GitHub account', () => {
const contributor = contributors.nologin
const {options} = fixtures()

Expand Down
4 changes: 2 additions & 2 deletions src/repo/__tests__/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test('Throw error when missing enterprise authentication', async () => {
)
})

test('handle API rate github errors', async () => {
test('handle API rate GitHub errors', async () => {
const githubErrorMessage =
"API rate limit exceeded for 0.0.0.0. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details."
nock('https://api.github.com').get('/users/nodisplayname').reply(200, {
Expand Down Expand Up @@ -177,7 +177,7 @@ test('append http when no absolute link is provided', async () => {
expect(info.profile).toBe('http://www.github.com/nodisplayname')
})

test('retrieve user from a different github registry', async () => {
test('retrieve user from a different GitHub registry', async () => {
nock('http://github.myhost.com:3000/api/v3')
.get('/users/nodisplayname')
.reply(200, {
Expand Down

0 comments on commit d517440

Please sign in to comment.