File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const _get = require('just-safe-get')
66const _set = require ( 'just-safe-set' )
77const _has = require ( 'lodash.has' )
88const errcode = require ( 'err-code' )
9+ const errors = require ( './errors' )
910
1011const configKey = new Key ( 'config' )
1112
@@ -27,7 +28,7 @@ module.exports = (store) => {
2728 const encodedValue = await store . get ( configKey )
2829 const config = JSON . parse ( encodedValue . toString ( ) )
2930 if ( key !== undefined && ! _has ( config , key ) ) {
30- throw new Error ( `Key ${ key } does not exist in config` )
31+ throw new errors . NotFoundError ( `Key ${ key } does not exist in config` )
3132 }
3233
3334 const value = key !== undefined ? _get ( config , key ) : config
Original file line number Diff line number Diff line change 11'use strict'
22
3+ /**
4+ * Error raised when requested item is not found.
5+ */
6+ class NotFoundError extends Error {
7+ constructor ( message ) {
8+ super ( message )
9+ this . name = 'NotFoundError'
10+ this . code = 'ERR_NOT_FOUND'
11+ this . message = message
12+ }
13+ }
14+
15+ NotFoundError . code = 'ERR_NOT_FOUND'
16+ exports . NotFoundError = NotFoundError
17+
318exports . ERR_REPO_NOT_INITIALIZED = 'ERR_REPO_NOT_INITIALIZED'
419exports . ERR_REPO_ALREADY_OPEN = 'ERR_REPO_ALREADY_OPEN'
520exports . ERR_REPO_ALREADY_CLOSED = 'ERR_REPO_ALREADY_CLOSED'
Original file line number Diff line number Diff line change @@ -26,5 +26,15 @@ module.exports = (repo) => {
2626 }
2727 } )
2828 } )
29+ describe ( '.get' , ( ) => {
30+ it ( 'should throw NotFoundError when key does not exist' , async ( ) => {
31+ try {
32+ await repo . config . get ( 'someRandomKey' )
33+ throw new Error ( 'Should have thrown' )
34+ } catch ( err ) {
35+ expect ( err . code ) . to . equal ( 'ERR_NOT_FOUND' )
36+ }
37+ } )
38+ } )
2939 } )
3040}
You can’t perform that action at this time.
0 commit comments