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

Error Prefix Not Shown With Error Messages #885

Closed
danielhelfand opened this issue Jun 9, 2020 · 3 comments
Closed

Error Prefix Not Shown With Error Messages #885

danielhelfand opened this issue Jun 9, 2020 · 3 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@danielhelfand
Copy link
Contributor

danielhelfand commented Jun 9, 2020

Bug report

An error prefix is not displayed with error messages. Only the error message is shown.

Cobra handles error messages by default if SilenceErrors is false, but kn handles errors in main.go and sets SilenceErrors to true for the root command.

By removing the SilenceErrors from the root command, there would be no need to print error messages in main.go, and it could be rewrote as follows:

func main() {
	defer cleanup()
	rand.Seed(time.Now().UnixNano())
	
        kn, err := core.NewDefaultKnCommand()
        if err != nil {
            os.Exit(1)
        }

	if err = kn.Execute(); err != nil {
	    os.Exit(1)
	}
}

Then Cobra would properly attach the error prefix to messages by default for all errors.

Expected behavior

An error prefix should be displayed before error messages.

kn service l
Error: unknown sub-command "l" for "kn service"

Steps to reproduce the problem

Produce an error of any kind:

kn service l
unknown sub-command "l" for "kn service"

kn version

What's currently in master as of v0.15.1.

@danielhelfand danielhelfand added the kind/bug Categorizes issue or PR as related to a bug. label Jun 9, 2020
@navidshaikh
Copy link
Collaborator

Thanks @danielhelfand! Linking it with generic tracker for error handling issue #213 to be addressed.

@rhuss
Copy link
Contributor

rhuss commented Jun 16, 2020

I think this has been fixed already in the latest PR merged with #877 and improved in #887 . There is now only a single point where the error is printed (in main.go). It's used to customize the error message, I found the printing out of errors at different levels in the stack confusing (which sometimes lead to double error printing when e.g. the error message was printed but still the error was propagated upwards). SilenceError in combination with a single point of error printing is imo the better solution.

@danielhelfand could you please check, whether the #887 fixes the issues that you have encountered ?

@github-actions
Copy link

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

3 participants