File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /** Error names commonly thrown by prompt libraries when the user presses Ctrl+C. */
12const PROMPT_ABORT_ERROR_NAMES = new Set ( [
23 'ExitPromptError' ,
34 'AbortPromptError' ,
45 'PromptAbortError' ,
56] ) ;
67
8+ /** Thrown when the user explicitly cancels a command (e.g. via Ctrl+C or a confirmation prompt). */
79export class UserCancelledError extends Error {
810 constructor ( message : string = 'User cancelled the current command.' ) {
911 super ( message ) ;
1012 this . name = 'UserCancelledError' ;
1113 }
1214}
1315
16+ /** Return `true` when `error` is a prompt-library abort (e.g. user pressed Escape or Ctrl+C). */
1417export function isPromptAbortError ( error : unknown ) : boolean {
1518 if ( ! ( error instanceof Error ) ) {
1619 return false ;
@@ -23,10 +26,12 @@ export function isPromptAbortError(error: unknown): boolean {
2326 return / f o r c e c l o s e d t h e p r o m p t | p r o m p t w a s c a n c e l e d | c a n c e l e d p r o m p t / i. test ( error . message ) ;
2427}
2528
29+ /** Return `true` when `error` represents a user-initiated cancellation. */
2630export function isUserCancelledError ( error : unknown ) : boolean {
2731 return error instanceof UserCancelledError || isPromptAbortError ( error ) ;
2832}
2933
34+ /** Safely extract a human-readable message from an unknown thrown value. */
3035export function getErrorMessage (
3136 error : unknown ,
3237 fallback : string = 'Something went wrong. Please try again.' ,
You can’t perform that action at this time.
0 commit comments