File tree 2 files changed +20
-7
lines changed
2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -163,7 +163,10 @@ export const overwrite = async (
163
163
return write ( filePath , jsonContent , indentationLevel ) ;
164
164
}
165
165
166
- const notAValidObjectError = new JSONFileHandlerError ( 'NOT_A_VALID_OBJECT' ) ;
166
+ const notAValidObjectError = new JSONFileHandlerError (
167
+ 'NOT_A_VALID_OBJECT' ,
168
+ filePath
169
+ ) ;
167
170
return Promise . reject ( notAValidObjectError ) ;
168
171
} ;
169
172
@@ -183,11 +186,11 @@ export const read = async (filePath: string): Promise<object> => {
183
186
}
184
187
185
188
if ( stringifiedJsonContent . length === 0 ) {
186
- const emptyFileError = new JSONFileHandlerError ( 'EMPTY_FILE' ) ;
189
+ const emptyFileError = new JSONFileHandlerError ( 'EMPTY_FILE' , filePath ) ;
187
190
return Promise . reject ( emptyFileError ) ;
188
191
}
189
192
190
- const notAJsonError = new JSONFileHandlerError ( 'NOT_A_JSON' ) ;
193
+ const notAJsonError = new JSONFileHandlerError ( 'NOT_A_JSON' , filePath ) ;
191
194
return Promise . reject ( notAJsonError ) ;
192
195
} ;
193
196
@@ -223,7 +226,10 @@ export const join = async (
223
226
}
224
227
}
225
228
226
- const notAValidObjectError = new JSONFileHandlerError ( 'NOT_A_VALID_OBJECT' ) ;
229
+ const notAValidObjectError = new JSONFileHandlerError (
230
+ 'NOT_A_VALID_OBJECT' ,
231
+ filePath
232
+ ) ;
227
233
return Promise . reject ( notAValidObjectError ) ;
228
234
} ;
229
235
Original file line number Diff line number Diff line change 1
1
import { JSONFileHandlerErrorMessage } from './enums' ;
2
2
3
- /** Extends `Error` by adding a `code` property for ease of debugging, as
4
- * `SystemError` also contains that property .
3
+ /** Extends `Error` by adding the `code` and `path` properties that are present
4
+ * in `SystemError`.
5
5
*/
6
6
export class JSONFileHandlerError extends Error {
7
7
code : string ;
8
+ /** The file that caused the error (useful when multiple files are
9
+ * manipulated) */
10
+ path : string ;
8
11
9
- constructor ( code : keyof typeof JSONFileHandlerErrorMessage ) {
12
+ constructor (
13
+ code : keyof typeof JSONFileHandlerErrorMessage ,
14
+ filePath : string
15
+ ) {
10
16
const message = JSONFileHandlerErrorMessage [ code ] ;
11
17
super ( message ) ;
12
18
this . code = code ;
19
+ this . path = filePath ;
13
20
}
14
21
}
You can’t perform that action at this time.
0 commit comments