Skip to content
This repository was archived by the owner on Nov 30, 2026. It is now read-only.

Fix invalid token error - #297

Merged
joetannenbaum merged 4 commits into
laravel:mainfrom
JonPurvis:fix-invalid-token-error
Nov 24, 2026
Merged

joetannenbaum merged 4 commits into
laravel:mainfrom
JonPurvis:fix-invalid-token-error

Conversation

@JonPurvis

Copy link
Copy Markdown
Contributor

A revoked or invalid API token used to crash commands with a Saloon UnauthorizedException stack trace.

This PR updates BaseCommand so it now catches it and prints a clean error that tells the user to run cloud auth, or to check LARAVEL_CLOUD_TOKEN if the token came from there.

In --json or non-interactive runs, the error is written as JSON to stderr.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 22:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The 401 handler can still throw on non-JSON responses and incorrectly blame a valid environment token when a stored token fails.

2 open issues
What changed in this PR

This PR centralizes invalid-token handling in BaseCommand so Cloud CLI commands provide recovery guidance instead of an unauthorized-exception stack trace.

Changes:

  • Catches unauthorized responses and routes them through the existing error output, including JSON on stderr for headless runs.
  • Adds guidance for stored and environment-provided tokens.
  • Adds tests for command failure and recovery messages.
File Description
tests/​Feature/​UnauthorizedResponseTest.php Tests rejected-token handling and token-source guidance.
app/​Commands/​BaseCommand.php Catches unauthorized responses and formats recovery messages.

Review effort: Balanced

Comment thread app/Commands/BaseCommand.php Resolved
Comment thread app/Commands/BaseCommand.php Resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 23:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

A revoked saved token can incorrectly trigger advice to change a valid environment token, and command-level tests lack assertions for error content and output routing across interactive, JSON, and non-interactive modes.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Identify the credential that caused token-list authentication failure

app/​Commands/​BaseCommand.php:243

When the environment token is valid but a saved token is revoked, cloud auth:token --list requests organization details for both tokens (AuthToken::listTokens). A 401 from the saved-token request therefore takes this branch and tells the user to change or unset their working environment token. Please determine the source from the failing request's credential rather than the presence of the environment variable.

Medium severity Assert command-level error output for JSON and non-interactive modes

tests/​Feature/​UnauthorizedResponseTest.php:52

This command-level test checks only the exit status, while the remaining tests invoke the message helper directly. None verifies the central output contract: a clean interactive error, or JSON on stderr with no stdout output for --json and non-interactive runs. Please add command-level output assertions for those modes so incorrect routing, serialization, or omitted remediation causes a regression failure.

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 16, 2026 23:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human review is needed because the tests do not verify that --json and --no-interaction emit the expected JSON error to stderr while leaving stdout empty.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 16, 2026 23:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the centralized handling of rejected Laravel Cloud API tokens.

No open issues 🎉

Review effort: Balanced

@joetannenbaum

Copy link
Copy Markdown
Collaborator

Thank you!

@joetannenbaum
joetannenbaum merged commit e4183cc into laravel:main Nov 24, 2026
3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants