Improve the output when non-existent command used#662
Merged
Conversation
Currently we just output something like `unexpected argument "foo"` then do nothing, but we should; - suggest "did you mean..." when a clear typo is the issue - output the command help when an obscure argument/subcommand is used
PriyaSudip
reviewed
Feb 24, 2026
|
|
||
| var parseErr *kong.ParseError | ||
| if errors.As(err, &parseErr) && !strings.Contains(err.Error(), "did you mean") { | ||
| _ = parseErr.Context.PrintUsage(false) |
Contributor
There was a problem hiding this comment.
Should we check if PrintUsage throws an error?
Also, going through the doc, if the flag is true, it only gives a summary of the error https://pkg.go.dev/github.com/alecthomas/kong#Context.PrintUsage, Will it be helpful to locate the issue faster than having a full stack trace?
Contributor
Author
There was a problem hiding this comment.
PrintUsage(true) outputs the short version of the help menu, rather than the full available output, eg:
go run . pipeline loooooo
Usage: bk pipeline <command> [flags]
Manage pipelines
Run "bk pipeline --help" for more information.
Error: unexpected argument loooooo
exit status 1Re: error return on PrintUsage(), it only throws an error when io.Writer fails, which means the terminal itself has disappeared/crashed.
PriyaSudip
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Currently we just output something like
unexpected argument "foo"then do nothing, but we should;Changes
did you meanUsageOnErroras we never fell through to it anyway due to lack ofFatalTesting
go fmt ./...)