Skip to content

[12.x] Fix cache:clear command exit code on failure#57988

Merged
taylorotwell merged 1 commit into
laravel:12.xfrom
alies-dev:fix/cache-clear-exit-code
Dec 1, 2025
Merged

[12.x] Fix cache:clear command exit code on failure#57988
taylorotwell merged 1 commit into
laravel:12.xfrom
alies-dev:fix/cache-clear-exit-code

Conversation

@alies-dev

@alies-dev alies-dev commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Summary

The cache:clear command was returning void (which Symfony Console interprets as exit code 0) even when the cache flush operation failed. While the error message is printed to stdout, the exit code doesn't reflect the failure, which breaks the standard Unix convention that automation tools rely on.

Problem

// Before: returns void (exit code 0) even on failure
if (! $successful) {
    return $this->components->error('Failed to clear cache...');
}

The $this->components->error() method returns void, so the command exits with code 0 despite the failure. Tools can still detect failure by parsing stdout, but this is fragile compared to checking exit codes.

Solution

// After: properly returns exit code 1 on failure
if (! $successful) {
    $this->components->error('Failed to clear cache...');
    return self::FAILURE;
}

This follows the pattern used consistently in other Laravel commands like db:wipe, migrate, db:seed, etc.

Changes

  • Return self::FAILURE (exit code 1) when cache flush fails
  • Return self::SUCCESS (exit code 0) on successful cache clear
  • Update PHPDoc return type from void to int

The cache:clear command was returning void (exit code 0) even when the cache flush operation failed. This made it impossible for automation tools and CI/CD pipelines to detect cache clear failures.

Changes:
- Return self::FAILURE when cache flush fails
- Return self::SUCCESS on successful cache clear
- Update return type from void to int
@taylorotwell taylorotwell merged commit c04df13 into laravel:12.x Dec 1, 2025
76 checks passed
@alies-dev alies-dev deleted the fix/cache-clear-exit-code branch December 1, 2025 17:46
akyrey pushed a commit to akyrey/framework that referenced this pull request Dec 29, 2025
The cache:clear command was returning void (exit code 0) even when the cache flush operation failed. This made it impossible for automation tools and CI/CD pipelines to detect cache clear failures.

Changes:
- Return self::FAILURE when cache flush fails
- Return self::SUCCESS on successful cache clear
- Update return type from void to int
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.

2 participants