MCPcopy
hub / github.com/afar1/fieldtheory-cli / safe

Function safe

src/cli.ts:730–745  ·  view source on GitHub ↗

Wrap an async action with graceful error handling.

(fn: (...args: any[]) => Promise<void>)

Source from the content-addressed store, hash-verified

728
729/** Wrap an async action with graceful error handling. */
730function 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
747function parsePositiveInteger(value: string): number {
748 const parsed = Number(value);

Callers 2

buildCliFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected