citty icon indicating copy to clipboard operation
citty copied to clipboard

Add support for custom error handling

Open ItsMeBrianD opened this issue 2 years ago • 1 comments

Describe the feature

When using subcommands, it would be nice to have error handling bubble up, much like setup and cleanup

Additional information

  • [X] Would you be willing to help implement this feature?

ItsMeBrianD avatar Jan 11 '24 18:01 ItsMeBrianD

An ideia would be rethrow the error in this line:

https://github.com/unjs/citty/blob/fea15c4b02cebd5f454908bad4b6b7ba694ee9ca/src/main.ts#L34-L36

This way:

 if (!isCLIError) { 
   throw error; 
 } 

And then we can handle the error in the main script:

 runMain(main).catch((err) => { 
     // handle error
})

zzhenryquezz avatar Jul 30 '24 15:07 zzhenryquezz