File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -12,19 +12,21 @@ const program = new Command()
12
12
. description ( 'CLI tool to generate and lint Node.js API documentation' ) ;
13
13
14
14
/**
15
- * Returns a wrapped version of the given async function that catches and rethrows any errors.
15
+ * Wraps a function to catch both synchronous and asynchronous errors.
16
16
*
17
- * @function
18
- * @param {Function } fn - The async function to wrap.
19
- * @returns {Function } A new function that calls `fn` with any given arguments and rethrows errors.
17
+ * @param {Function } fn - The function to wrap. Can be synchronous or return a Promise.
18
+ * @returns {Function } A new function that handles errors and logs them.
20
19
*/
21
20
const errorWrap =
22
21
fn =>
23
- ( ...args ) =>
24
- fn ( ...args ) . catch ( e => {
25
- console . error ( e ) ;
22
+ async ( ...args ) => {
23
+ try {
24
+ return await fn ( ...args ) ;
25
+ } catch ( err ) {
26
+ console . error ( err ) ;
26
27
process . exit ( 1 ) ;
27
- } ) ;
28
+ }
29
+ } ;
28
30
29
31
// Registering generate and lint commands
30
32
commands . forEach ( ( { name, description, options, action } ) => {
You can’t perform that action at this time.
0 commit comments