-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI cleanup: exit-1 on error, and use consistent error printing every…
…where (#6322) Clean-up and follow-up from #6285 and #6318, but only part 1 of [probably 2]. The next part will change our ErrorAndExit calls into error returns, so we get chains of causes rather than just one message when a fatal error is hit. If there's a part 3, maybe it'll use https://github.com/bracesdev/errtrace or a https://github.com/pkg/errors-like wrapper to collect useful stack traces along with the error returns, to bring back `CADENCE_CLI_SHOW_STACKS` for all errors. --- Contains three major changes: 1. creates some standard "literally all CLIs" tooling in common/commoncli (to avoid conflicts with "common" and "cli") 2. moves `cli.NewApp()` and `PrintableError` into commoncli (as `New` and `Problem`) 3. fancy shmancy wrapped error printing with indentation, nested-error cleanup, and colors (we had colors before) 1 and 2 are pretty straightforward, and I've added a simple lint to block using urfave directly to make CLIs (to prevent accidentally using it in the future). 3 is an attempt at "what if our error messages were similar but less bad". And it also serves as an example of what you can do with enough force with wrapped errors. --- Ultimately, this gives us (the ability to) have errors print like this: ``` Error: the most-recent cause of the problem Error details: wrapped error details if they exist Error: another commoncli.Problem from further down the stack Error details: and other wrapped errors that it may contain ``` Rather than like this: ``` Error: the most-recent cause of the problem Error details: wrapped error: details if they exist: another commoncli.Problem from further down the stack: and other wrapped errors: that it may contain ``` Because it looks "in the same spirit" as the printing before, but is hopefully more readable. And hopefully it also helps show enough error-spelunking details that someone can figure out much fancier and more structured errors later, if desired. This also ends up changing the main server binary to use this same fancy error printing, where before it did not: ``` ❯ ./cadence-server start 2024/10/02 22:26:06 Loading config; env=development,zone=,configDir=./config 2024/10/02 22:26:06 Loading configFiles=[./config/base.yaml ./config/development.yaml] 2024/10/02 22:26:06 [WARN] dcRedirectionPolicy config is deprecated. Please replace it with clusterRedirectionPolicy. 2024/10/02 22:26:06 gocql: unable to dial control conn 127.0.0.1:9042: dial tcp 127.0.0.1:9042: connect: connection refused Error: cassandra schema version compatibility check failed Error details: creating CQL client gocql: unable to create session: control: unable to connect to initial hosts: dial tcp 127.0.0.1:9042: connect: connection refused ``` vs before: ``` ❯ ./cadence-server start 2024/10/02 22:27:58 Loading config; env=development,zone=,configDir=./config 2024/10/02 22:27:58 Loading configFiles=[./config/base.yaml ./config/development.yaml] 2024/10/02 22:27:58 [WARN] dcRedirectionPolicy config is deprecated. Please replace it with clusterRedirectionPolicy. 2024/10/02 22:27:58 gocql: unable to dial control conn 127.0.0.1:9042: dial tcp 127.0.0.1:9042: connect: connection refused cassandra schema version compatibility check failed: creating CQL client: gocql: unable to create session: control: unable to connect to initial hosts: dial tcp 127.0.0.1:9042: connect: connection refused ``` which seems like probably a positive change. It is colorized, but fatih is smart enough to remove it when piped, and removing color from this binary all the time is fairly easy if we want.
- Loading branch information
Showing
33 changed files
with
607 additions
and
267 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.