cobra
cobra copied to clipboard
feat: added custom error handler function
Sometimes I want to manually define a way that an error is presented to the user (for instance to change color output and such). This PR adds a way to do so via the new SetErrorHandlerFunc
method
@jpmcb thanks for your feedback. i created a gist where i can show you an example where this feature would be useful: https://gist.github.com/alexraileanu/200a4473653efa8fbda6e555bd3fc428.
in the screenshot below, you can see that my custom error handlers have different colored messages, however the Error:
prefix is added to both. my code, provides a way to give the developer full control over what is output to the user in case of an error.

please let me know if you need any more clarification as i would really like to make use of this feature :)
@jpmcb @marckhouzam kindly requesting a review of this as i'd very much like to have this feature in my project
@jpmcb sorry for the mess, i did some mistakes on my side of github but it looks like it's all good now.
The Cobra project currently lacks enough contributors to adequately respond to all PRs. This bot triages issues and PRs according to the following rules:
- After 60d of inactivity, lifecycle/stale is applied. - After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied and the PR is closed. You can:
- Make a comment to remove the stale label and show your support. The 60 days reset. - If a PR has lifecycle/rotten and is closed, comment and ask maintainers if they'd be interested in reopening.
As we have very few maintainers, and those have very little time, we've decided to remove the auto-close configuration. I'm re-opening this PR since it was closed automatically.