Skip to content

Commit

Permalink
Update CONTRIBUTING_JS.md
Browse files Browse the repository at this point in the history
add section on error codes
Ref. ipfs/js-ipfs#2547 (comment)
  • Loading branch information
lidel authored Nov 4, 2019
1 parent 051f97c commit a56d710
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CONTRIBUTING_JS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Our toolkit for each of these is not set in stone, and we don't plan to halt our
- [Guidelines](#guidelines)
- [Supported versions](#supported-versions)
- [Linting & Code Style](#linting--code-style)
- [Error Codes](#error-codes)
- [Dependency Versions](#dependency-versions)
- [Testing](#testing)
- [Releasing](#releasing)
Expand Down Expand Up @@ -100,6 +101,25 @@ However, we've added an extra linting rule: Enforce the use of [strict mode](htt

Using [aegir-lint](#aegir) will help you do this easily; it automatically lints your code.

#### Error Codes

When introducing a new error code that may be useful outside of the current scope, make sure it is defined in a named variable and can be exported and used in other places. This enables others to reuse those definitions and decreases number of hardcoded values across our codebases. For example:

```js
const { Errors } = require('interface-datastore')

// throw predefined errors if possible
if (!value) {
throw Errors.notFoundError()
}

// compare value from
const ERR_NOT_FOUND = Errors.notFoundError().code
if (err.code === ERR_NOT_FOUND) {
// handle
}
```

#### Dependency Versions

Our rule is: Use ~ for everything below 1.0.0 and ^ for everything above 1.0.0. If you find a package.json that is not following this rule, please submit a PR.
Expand Down

0 comments on commit a56d710

Please sign in to comment.