Skip to content

Commit f20a54d

Browse files
authored
Merge pull request #19270 from nextcloud/backport/19241/stable17
[stable17] Make sure to catch php errors during job execution
2 parents ac9f060 + 73fa863 commit f20a54d

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

lib/private/BackgroundJob/Job.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function execute($jobList, ILogger $logger = null) {
6363

6464
$logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']);
6565
$jobList->setExecutionTime($this, $timeTaken);
66-
} catch (\Exception $e) {
66+
} catch (\Throwable $e) {
6767
if ($logger) {
6868
$logger->logException($e, [
6969
'app' => 'core',

tests/lib/BackgroundJob/JobTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ public function testRemoveAfterException() {
3939
$this->assertCount(1, $jobList->getAll());
4040
}
4141

42+
public function testRemoveAfterError() {
43+
$jobList = new DummyJobList();
44+
$job = new TestJob($this, function () {
45+
$test = null;
46+
$test->someMethod();
47+
});
48+
$jobList->add($job);
49+
50+
$logger = $this->getMockBuilder(ILogger::class)
51+
->disableOriginalConstructor()
52+
->getMock();
53+
$logger->expects($this->once())
54+
->method('logException')
55+
->with($this->isInstanceOf(\Throwable::class));
56+
57+
$this->assertCount(1, $jobList->getAll());
58+
$job->execute($jobList, $logger);
59+
$this->assertTrue($this->run);
60+
$this->assertCount(1, $jobList->getAll());
61+
}
62+
4263
public function markRun() {
4364
$this->run = true;
4465
}

0 commit comments

Comments
 (0)