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()
1212 . description ( 'CLI tool to generate and lint Node.js API documentation' ) ;
1313
1414/**
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.
1616 *
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.
2019 */
2120const errorWrap =
2221 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 ) ;
2627 process . exit ( 1 ) ;
27- } ) ;
28+ }
29+ } ;
2830
2931// Registering generate and lint commands
3032commands . forEach ( ( { name, description, options, action } ) => {
You can’t perform that action at this time.
0 commit comments