Skip to content

Conversation

@sammuti
Copy link
Contributor

@sammuti sammuti commented Dec 31, 2025

Emit proper error message for not logged in when running cmd
eg:

⠙ Setting up runtime environment...Oh no! You aren't authorized to do that! Are you logged in? Run `tower login` to login.
⠹ Setting up runtime environment...Error: fetching secrets failed

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves error handling by replacing generic error messages with proper error reporting through output::tower_error(), ensuring users receive appropriate feedback (e.g., when not logged in) when commands fail.

Key Changes:

  • Replaced generic "There was a problem with the Tower API" messages with output::tower_error() calls
  • Converted if let patterns to match expressions for consistent error handling
  • Added explicit std::process::exit(1) calls after error handling

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
crates/tower-cmd/src/secrets.rs Updated error handling in do_create, do_delete, and encrypt_and_create_secret to use tower_error() and explicit process exits
crates/tower-cmd/src/run.rs Replaced debug logging with tower_error() calls in get_secrets and get_catalogs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@bradhe bradhe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small things, it's on the right track.

  1. We should move the logic for error handling up a level in the get_secrets API wrapper. We don't want the API logic managing the output state.
  2. Let's create a tower_error_and_die function and use it instead of calling exit directly to normalize exit codes. secrets::do_create should be updated to address this I think.

@sammuti
Copy link
Contributor Author

sammuti commented Jan 2, 2026

@bradhe I've made an update to refactor spinner and error handling to be more consistent everywhere while taking your feedback into account. With this change all commands look like follows with login error

➜  14-dbt-core-ecommerce-analytics git:(testing-examples-updates) ✗ /usr/bin/env bash /Users/vim/projects/tower-examples/14-dbt-core-ecommerce-analytics/command-test.sh
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.28s
     Running `/Users/vim/projects/tower-cli/target/debug/tower environments list`
✘ Listing environments... Failed!
Error: Listing environments failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
     Running `/Users/vim/projects/tower-cli/target/debug/tower environments create --name testing`
✘ Creating environment Failed!
Error: Creating environment failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
     Running `/Users/vim/projects/tower-cli/target/debug/tower secrets list`
✘ Listing secrets... Failed!
Error: Listing secrets failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `/Users/vim/projects/tower-cli/target/debug/tower secrets create --name test-secret --value test123`
✘ Creating secret... Failed!
Error: Fetching secrets key failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
     Running `/Users/vim/projects/tower-cli/target/debug/tower apps list`
✘ Listing apps... Failed!
Error: Listing apps failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
     Running `/Users/vim/projects/tower-cli/target/debug/tower apps create --name test-app --description Test`
✘ Creating app Failed!
Error: Creating app failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `/Users/vim/projects/tower-cli/target/debug/tower apps delete test-app`
✘ Deleting app Failed!
Error: Deleting app failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `/Users/vim/projects/tower-cli/target/debug/tower deploy`
✘ Checking app... Failed!
Error: Fetching app details failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
     Running `/Users/vim/projects/tower-cli/target/debug/tower run`
✘ Scheduling run... Failed!
Error: Scheduling run failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `/Users/vim/projects/tower-cli/target/debug/tower schedules list`
✘ Listing schedules... Failed!
Error: Listing schedules failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
     Running `/Users/vim/projects/tower-cli/target/debug/tower schedules create --app myapp --cron '0 0 * * *'`
✘ Creating schedule Failed!
Error: Creating schedule failed because you are not logged into Tower. Please run 'tower login' first.
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `/Users/vim/projects/tower-cli/target/debug/tower schedules delete SCHEDULE_ID`
✘ Deleting schedule Failed!
Error: Deleting schedule failed because you are not logged into Tower. Please run 'tower login' first.

Copy link
Contributor

@bradhe bradhe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally good moving forward with what we have here; however, there's one improvement I suggested. It'd be ideal if you could implement that, then land this thing!

@sammuti sammuti merged commit 9ff1110 into develop Jan 2, 2026
5 checks passed
@sammuti sammuti deleted the chore/TOW-1275 branch January 2, 2026 19:14
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