Skip to content

Error Prefix Not Shown With Error Messages #885

@danielhelfand

Description

@danielhelfand

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions