Skip to content

fix: wrong RequestException import in 7 commands + ApplicationUpdate error handling#42

Open
JoshSalway wants to merge 1 commit intolaravel:mainfrom
JoshSalway:fix/application-bug-fixes
Open

fix: wrong RequestException import in 7 commands + ApplicationUpdate error handling#42
JoshSalway wants to merge 1 commit intolaravel:mainfrom
JoshSalway:fix/application-bug-fixes

Conversation

@JoshSalway
Copy link

@JoshSalway JoshSalway commented Mar 16, 2026

Summary

Fixes two bugs discovered while writing comprehensive test coverage for #41.

Closes #50
Closes #51

Bug 1: Wrong RequestException import in 7 commands

7 commands import Illuminate\Http\Client\RequestException (Laravel HTTP client) but the CLI uses Saloon, which throws Saloon\Exceptions\Request\RequestException. The catch blocks never match, so API errors during delete/verify operations crash with unhandled exceptions instead of showing user-friendly error messages.

Affected commands:

  • ApplicationDelete
  • EnvironmentDelete
  • DatabaseClusterDelete
  • DomainDelete
  • DomainVerify
  • InstanceDelete
  • BackgroundProcessDelete

Fix: Replace the import in all 7 files.

Bug 2: ApplicationUpdate has no error handling

ApplicationCreate uses loopUntilValid to catch validation errors, but ApplicationUpdate has no equivalent. API 422/500 responses propagate as uncaught RequestException, showing raw stack traces to users.

Fix: Added try/catch RequestException around both the update and avatar upload API calls.

How these bugs were found

While writing feature tests following the Laravel Forge CLI pattern (1 test file per command), we discovered these bugs:

  • Tests for ApplicationDelete with a mocked 500 response passed without triggering the catch block — the wrong exception class was being caught
  • Tests for ApplicationUpdate with a mocked 422 response threw an unhandled exception instead of showing a validation error

Test plan

  • ./vendor/bin/pest — all 31 existing tests pass
  • ./vendor/bin/phpstan analyse — 0 errors
  • Delete an application when the API returns a 500 — should show "Failed to delete application: ..." instead of a stack trace
  • Update an application with an invalid name — should show error message instead of stack trace

Generated with Claude Code

…to ApplicationUpdate

Bug 1: 7 commands imported Illuminate\Http\Client\RequestException instead of
Saloon\Exceptions\Request\RequestException. Since the Connector uses Saloon's
AlwaysThrowOnErrors trait, API errors throw Saloon's exception — which was
never caught. Affected commands:
- ApplicationDelete
- EnvironmentDelete
- DatabaseClusterDelete
- DomainDelete
- DomainVerify
- InstanceDelete
- BackgroundProcessDelete

Bug 2: ApplicationUpdate had no error handling for API failures. Unlike
ApplicationCreate which uses loopUntilValid, update let 422/500 responses
propagate as uncaught exceptions, showing raw stack traces. Added try/catch
with user-friendly error messages.

Both bugs were discovered while writing comprehensive test coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
JoshSalway added a commit to JoshSalway/cloud-cli that referenced this pull request Mar 16, 2026
Increases test coverage from 3/87 commands (~3%) to 43/87 (~49%),
following the Laravel Forge CLI pattern of one test file per command.

Commands now tested:
- Auth: auth, auth:token
- Application: create, get, update, delete
- Environment: create, get, list, update, delete, variables
- Domain: create, delete, list, verify
- Database: cluster create/delete/list, database create/delete/list
- Cache: create, delete, list
- Bucket: create, delete, list
- Instance: create, delete, list, update
- WebSocket: cluster create/delete/list, application create/delete
- Background Process: create, delete, list
- Command: run, list

Bugs documented in tests (skipped with references to PR laravel#42):
- 7 commands catch wrong RequestException class (Illuminate vs Saloon)
- ApplicationUpdate has no error handling for API failures
- DatabaseDelete catches Throwable which swallows CommandExitException
- DomainCreate missing non-interactive defaults
- CacheDelete/BucketDelete missing --json option

Refs laravel#41

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JoshSalway JoshSalway changed the title Fix wrong RequestException import in 7 commands + add error handling to ApplicationUpdate fix: wrong RequestException import in 7 commands + ApplicationUpdate error handling Mar 16, 2026
@JoshSalway

This comment was marked as spam.

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.

Bug: ApplicationUpdate has no error handling for API failures Bug: 7 commands catch wrong RequestException class (Illuminate vs Saloon)

1 participant