Wrap an async action with graceful error handling.
(fn: (...args: any[]) => Promise<void>)
| 728 | |
| 729 | /** Wrap an async action with graceful error handling. */ |
| 730 | function safe(fn: (...args: any[]) => Promise<void>): (...args: any[]) => Promise<void> { |
| 731 | return async (...args: any[]) => { |
| 732 | try { |
| 733 | await fn(...args); |
| 734 | } catch (err) { |
| 735 | if (err instanceof PromptCancelledError) { |
| 736 | console.log(`\n ${err.message}\n`); |
| 737 | process.exitCode = err.exitCode; |
| 738 | return; |
| 739 | } |
| 740 | const msg = (err as Error).message; |
| 741 | console.error(`\n Error: ${msg}\n`); |
| 742 | process.exitCode = 1; |
| 743 | } |
| 744 | }; |
| 745 | } |
| 746 | |
| 747 | function parsePositiveInteger(value: string): number { |
| 748 | const parsed = Number(value); |
no outgoing calls
no test coverage detected