cobra icon indicating copy to clipboard operation
cobra copied to clipboard

feat: added custom error handler function

Open alexraileanu opened this issue 2 years ago • 6 comments

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

alexraileanu avatar Jul 05 '22 10:07 alexraileanu

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 05 '22 10:07 CLAassistant

@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.

image

please let me know if you need any more clarification as i would really like to make use of this feature :)

alexraileanu avatar Jul 18 '22 10:07 alexraileanu

@jpmcb @marckhouzam kindly requesting a review of this as i'd very much like to have this feature in my project

alexraileanu avatar Aug 24 '22 08:08 alexraileanu

@jpmcb sorry for the mess, i did some mistakes on my side of github but it looks like it's all good now.

alexraileanu avatar Oct 04 '22 09:10 alexraileanu

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.

github-actions[bot] avatar Dec 04 '22 00:12 github-actions[bot]

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.

marckhouzam avatar Dec 23 '23 20:12 marckhouzam