Skip to content

A process failing with the stop error strategy throws a FatalError: exit code 0, original exception lost, failed sub-processes not detected #220

Closed

Description

@njoubert-cleverage

Description

When a task fails with the stop error strategy (the default), the process manager throws a Symfony\Component\ErrorHandler\Error\FatalError. This has three consequences:

  • The command exits with code 0 when a process fails: FatalError is an \Error, not an \Exception, and the console application does not turn it into a non-zero exit code. A cron job, a CI job or a supervisor cannot detect failures. An unknown process code, which throws an \Exception, exits with code 1.
  • ProcessLauncherTask does not detect failed sub-processes: it relies on the sub-process exit code, so a sub-process failing in stop strategy is considered successful and the parent process ends with "executed successfully".
  • The original exception is lost: only its message (and file/line) is copied, it is not attached as previous. Its class, code and trace are lost, and a catch (\Exception) around ProcessManager::execute() does not catch the failure.

Reproduction

clever_age_process:
    configurations:
        arb.stop:
            tasks:
                entry:
                    service: '@CleverAge\ProcessBundle\Task\ConstantOutputTask'
                    options: { output: 'x' }
                    outputs: [ fail ]
                fail:
                    service: '@CleverAge\ProcessBundle\Task\TransformerTask'
                    options: { transformers: { date_format: { format: 'Y' } } }
        arb.launcher:
            tasks:
                values:
                    service: '@CleverAge\ProcessBundle\Task\ConstantIterableOutputTask'
                    options: { output: [ one ] }
                    outputs: [ launch ]
                launch:
                    service: '@CleverAge\ProcessBundle\Task\Process\ProcessLauncherTask'
                    options: { process: arb.stop.child }
        arb.stop.child:
            entry_point: fail
            tasks:
                fail:
                    service: '@CleverAge\ProcessBundle\Task\TransformerTask'
                    options: { transformers: { date_format: { format: 'Y' } } }
$ bin/console cleverage:process:execute arb.stop -v
In TransformerTrait.php line 63:
  [Symfony\Component\ErrorHandler\Error\FatalError (-1)]
  Process arb.stop has failed during process fail with message: 'Transformation 'date_format' have failed: Given value cannot be parsed into a date'.
$ echo $?
0

$ bin/console cleverage:process:execute arb.launcher
Process 'arb.launcher' executed successfully

Tested on main (1d202a2), PHP 8.5, Symfony 7.4.

Cause

ProcessManager::process():

throw new FatalError($m, -1, ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'type' => 500, 'message' => $exception->getMessage()]);

Proposed fix

  • Add a dedicated CleverAge\ProcessBundle\Exception\ProcessFailedException (a \RuntimeException implementing ProcessExceptionInterface), thrown instead of the FatalError, with the same message and the original exception as previous.
  • As a consequence, the command exits with code 1 on failure, and ProcessLauncherTask detects failed sub-processes.
  • Update the documentation (01-quick_start.md automation section, 04-advanced_workflow.md, 06-testing.md), add tests.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

Minor: the exception thrown on a stop failure is now a ProcessFailedException (\RuntimeException) instead of a FatalError (\Error). Code catching FatalError or \Error explicitly must catch ProcessFailedException instead (catch (\Throwable) keeps working). Scripts relying on the (wrong) exit code 0 of a failed process now get 1. symfony/error-handler is no longer used by src/ but is kept in composer.json.

Activity

  1. added a commit that references this issue on Sep 28, 2026
  2. added a commit that references this issue on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions