Skip to content

Conversation

@alies-dev
Copy link
Contributor

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

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
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