Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added custom error handler function #1751

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alexraileanu
Copy link

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

@CLAassistant
Copy link

CLAassistant commented Jul 5, 2022

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the size/M Denotes a PR that chanes 24-99 lines label Jul 5, 2022
Copy link
Collaborator

@jpmcb jpmcb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm interesting.

The code looks good, but I want to understand what this is trying to solve.

Can you provide a sample cobra program where something like this would be useful? Seems like you'd want to set this per command to handle different errors from different commands differently?

@alexraileanu
Copy link
Author

@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
Copy link
Author

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

@jpmcb jpmcb self-assigned this Oct 3, 2022
@alexraileanu alexraileanu reopened this Oct 4, 2022
@alexraileanu
Copy link
Author

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

@github-actions
Copy link

github-actions bot commented Dec 4, 2022

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.

@marckhouzam
Copy link
Collaborator

marckhouzam commented Dec 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Denotes a PR that chanes 24-99 lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants