Page MenuHomePhabricator

Maintenance scripts exit with 0 when an (uncaught) exception is encountered
Closed, ResolvedPublic

Description

Maintenance scripts exit with 0 when they fail due to an exception, as I just discovered on the snapshot hosts (Wikidata dumps failed there, but exited with 0).

Can be easily reproduced: Take any maintenance script and put throw new \Exception(); at the top of its execute function (I tested it with maintenance/refreshLinks.php but any script should work). It will exit with 0 (success).

This happens as MW sets its own exception handler (set_exception_handler):

$ cat test.php 
<?php

throw new Exception();

echo 1;
$ php test.php 
PHP Fatal error:  Uncaught Exception in /home/hoch_m/tmp/test.php:5
Stack trace:
#0 {main}
  thrown in /home/hoch_m/tmp/test.php on line 5
$ echo $?
255

but once we add an exception handler:

$ cat test.php 
<?php

set_exception_handler(function($e) {echo "ACK\n";});

throw new Exception();

echo 1;
$ php test.php 
ACK
$ echo $?
0

Event Timeline

Change 382181 had a related patch set uploaded (by Hoo man; owner: Hoo man):
[mediawiki/core@master] CLI: Make sure we don't exit with 0 when an exception is encountered

https://gerrit.wikimedia.org/r/382181

Change 382181 merged by jenkins-bot:
[mediawiki/core@master] CLI: Make sure we don't exit with 0 when an exception is encountered

https://gerrit.wikimedia.org/r/382181

hoo claimed this task.
hoo removed a project: Patch-For-Review.

This explains why postgres was seemingly passing on Travis CI when in fact it was broken (again).