Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Worker/SchedulerWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,17 @@ private function runCallback(TriggerInterface $trigger, string $service, string
$childExitCode = 0;
try {
($this->handler)($service, $taskName);
} catch (\Throwable) {
} catch (\Throwable $e) {
Comment thread
s2x marked this conversation as resolved.
$this->worker->log(sprintf(
'%s Task "%s" failed: [%s] %s in %s:%d\nStack trace:\n%s',
$this->worker->name,
Comment thread
s2x marked this conversation as resolved.
$taskName,
$e::class,
$e->getMessage(),
$e->getFile(),
$e->getLine(),
$e->getTraceAsString(),
));
$childExitCode = 1;
} finally {
// Release lock, cleanup and exit
Expand Down
43 changes: 43 additions & 0 deletions tests/SchedulerWorkerSigchldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,49 @@ public function testSchedulerWorkerUsesCorrectSignalPattern(): void
);
}

/**
* Structural test: verify SchedulerWorker logs exceptions in child process.
* This is a regression safety net for Issue #157 — if someone removes the
* exception logging or reverts to silently swallowing exceptions, this test
* catches it immediately.
*/
public function testSchedulerWorkerLogsExceptionsInChildProcess(): void
{
$sourceFile = dirname(__DIR__) . '/src/Worker/SchedulerWorker.php';
$this->assertFileExists($sourceFile);

$content = file_get_contents($sourceFile);
$this->assertNotFalse($content);

// Verify the catch block captures the exception variable
$this->assertStringContainsString(
'catch (\Throwable $e)',
$content,
'Catch block must capture exception variable for logging (Issue #157)',
);

// Verify the exception is logged via Worker::log()
$this->assertStringContainsString(
'$this->worker->log(sprintf(',
$content,
'Exception must be logged via Worker::log() in child process (Issue #157)',
);

// Verify the log message includes exception type
$this->assertStringContainsString(
'$e::class',
$content,
'Log message must include exception type for quick identification (Issue #157)',
);

// Verify the log message includes stack trace
$this->assertStringContainsString(
'$e->getTraceAsString()',
$content,
'Log message must include stack trace for full diagnostic information (Issue #157)',
);
}

/**
* Run a SIGCHLD test in an isolated PHP process to avoid PHPUnit
* state inheritance issues with pcntl_fork().
Expand Down