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

CLI cleanup: exit-1 on error, and use consistent error printing everywhere #6322

Merged
merged 3 commits into from
Oct 3, 2024

Conversation

Groxx
Copy link
Member

@Groxx Groxx commented Oct 2, 2024

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.

…where

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 future accidents).

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.
cmd/tools/cli/main.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 32.86713% with 192 lines in your changes missing coverage. Please review.

Please upload report for BASE (master@75bacb0). Learn more about missing BASE report.
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
tools/cli/workflow_commands.go 16.00% 42 Missing ⚠️
tools/cli/admin_commands.go 2.85% 34 Missing ⚠️
tools/cli/admin_elastic_search_commands.go 0.00% 14 Missing ⚠️
tools/cli/admin_failover_commands.go 0.00% 13 Missing ⚠️
tools/cli/domain_commands.go 47.82% 12 Missing ⚠️
tools/cli/workflow_batch_commands.go 0.00% 11 Missing ⚠️
tools/cli/admin_config_store_commands.go 0.00% 10 Missing ⚠️
tools/common/commoncli/cli.go 89.15% 7 Missing and 2 partials ⚠️
tools/cli/admin_db_scan_command.go 0.00% 8 Missing ⚠️
tools/cli/isolation-groups.go 0.00% 8 Missing ⚠️
... and 10 more
Additional details and impacted files
Files with missing lines Coverage Δ
tools/cli/app.go 98.72% <ø> (ø)
tools/cli/utils.go 55.02% <ø> (ø)
tools/cli/admin_kafka_commands.go 0.00% <0.00%> (ø)
tools/cli/cluster_commands.go 55.55% <0.00%> (ø)
tools/cli/admin_db_decode_thrift.go 72.46% <0.00%> (ø)
tools/cli/admin_dlq_commands.go 0.00% <0.00%> (ø)
tools/cli/admin_async_queue_commands.go 0.00% <0.00%> (ø)
tools/cli/admin_timers.go 0.00% <0.00%> (ø)
tools/cli/task_list_commands.go 45.00% <0.00%> (ø)
tools/cli/admin_task_list_commands.go 0.00% <0.00%> (ø)
... and 12 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75bacb0...5cf092a. Read the comment docs.

@Groxx Groxx merged commit add84ef into cadence-workflow:master Oct 3, 2024
19 of 20 checks passed
@Groxx Groxx deleted the errrets branch October 3, 2024 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants