This repository was archived by the owner on Sep 9, 2021. It is now read-only.
File tree 5 files changed +40
-1
lines changed 5 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 41
41
},
42
42
"dependencies" : {
43
43
"async" : " ^2.6.0" ,
44
+ "err-code" : " ^1.1.2" ,
44
45
"pull-defer" : " ^0.2.2" ,
45
46
"pull-stream" : " ^3.6.1" ,
46
47
"uuid" : " ^3.1.0"
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const errcode = require ( 'err-code' )
4
+
5
+ module . exports . ERR_DB_CANNOT_OPEN = ( err ) => {
6
+ err = err || new Error ( 'Cannot open database' )
7
+ return errcode ( err , 'ERR_CANNOT_OPEN_DB' )
8
+ }
9
+
10
+ module . exports . ERR_DB_DELETE_FAILED = ( err ) => {
11
+ err = err || new Error ( 'Delete failed' )
12
+ return errcode ( err , 'ERR_DB_DELETE_FAILED' )
13
+ }
14
+
15
+ module . exports . ERR_DB_WRITE_FAILED = ( err ) => {
16
+ err = err || new Error ( 'Write failed' )
17
+ return errcode ( err , 'ERR_DB_WRITE_FAILED' )
18
+ }
19
+
20
+ module . exports . ERR_NOT_FOUND = ( err ) => {
21
+ err = err || new Error ( 'Not Found' )
22
+ return errcode ( err , 'ERR_NOT_FOUND' )
23
+ }
Original file line number Diff line number Diff line change 4
4
const Key = require ( './key' )
5
5
const MemoryDatastore = require ( './memory' )
6
6
const utils = require ( './utils' )
7
+ const Errors = require ( './errors' )
7
8
8
9
exports . Key = Key
9
10
exports . MemoryDatastore = MemoryDatastore
10
11
exports . utils = utils
12
+ exports . Errors = Errors
11
13
12
14
/* ::
13
15
// -- Basics
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ const asyncFilter = require('./utils').asyncFilter
10
10
const asyncSort = require ( './utils' ) . asyncSort
11
11
const Key = require ( './key' )
12
12
13
+ // Errors
14
+ const Errors = require ( './errors' )
15
+ const ERR_NOT_FOUND = Errors . ERR_NOT_FOUND
16
+
13
17
class MemoryDatastore {
14
18
/* :: data: {[key: string]: Buffer} */
15
19
@@ -34,7 +38,7 @@ class MemoryDatastore {
34
38
}
35
39
36
40
if ( ! exists ) {
37
- return callback ( new Error ( 'No value' ) )
41
+ return callback ( ERR_NOT_FOUND ( ) )
38
42
}
39
43
40
44
callback ( null , this . data [ key . toString ( ) ] )
Original file line number Diff line number Diff line change @@ -111,6 +111,15 @@ module.exports = (test/* : Test */) => {
111
111
} )
112
112
] , done )
113
113
} )
114
+
115
+ it ( 'should return error with missing key' , ( done ) => {
116
+ const k = new Key ( '/does/not/exist' )
117
+ check ( store ) . get ( k , ( err ) => {
118
+ expect ( err ) . to . exist ( )
119
+ expect ( err ) . to . have . property ( 'code' , 'ERR_NOT_FOUND' )
120
+ done ( )
121
+ } )
122
+ } )
114
123
} )
115
124
116
125
describe ( 'delete' , ( ) => {
You can’t perform that action at this time.
0 commit comments