Skip to content

Let a failed app.php load fail with a non-zero status - #1112

Merged
markstory merged 2 commits into
5.xfrom
fix-config-load-exit
Oct 12, 2026
Merged

markstory merged 2 commits into
5.xfrom
fix-config-load-exit

Conversation

@dereuromark

@dereuromark dereuromark commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Fixes #1111.

config/bootstrap.php caught the exception from loading config/app.php and passed its message to exit(). With a string argument, exit() prints the string and ends with status 0. A broken app.php therefore made bin/cake commands report success, and on the web the message went out in a 200 response without reaching the error log.

The catch stays, but now ends with a failure. ErrorTrap and ExceptionTrap cannot handle it, since they are registered further down and need the Error config from app.php, so the failure is reported by hand:

  • CLI: the message goes to stderr and the exit status is 1.
  • Web: the message is written to the error log and the response is a 500 with an empty body, so visitors never see it, whatever display_errors says.

With config/app.php changed to return null;:

before after
bin/cake version message on stdout, exit 0 message on stderr, exit 1
GET / (built-in server) 200, message in body 500, empty body, message in error log

bootstrap.php caught the exception from loading config/app.php and passed
its message to exit(). exit() with a string prints it and ends with status
0, so a broken config made bin/cake commands report success, and the web
SAPI answered 200 with the message in the body and nothing in the log.

The error and exception traps are not registered yet at this point, since
they need the Error config from app.php. Dropping the catch leaves the
exception to PHP: status 255 on the CLI, a logged 500 on the web, with the
output governed by display_errors and log_errors.
@dereuromark dereuromark added this to the 5.x milestone Oct 12, 2026
@dereuromark

Copy link
Copy Markdown
Member Author

Actually, maybe a safer "web" way would be to do what PHP itself does here?

Keep the catch, but end with a failure: on the CLI the message goes to
stderr and the exit status is 1, on the web the message is written to the
error log and the response is a 500 with an empty body. This keeps the
one-line CLI output instead of a stack trace, and never shows the message
or file paths to visitors regardless of display_errors.

error_log() is skipped on the CLI because its default destination there is
stderr, which printed the message twice.
@markstory
markstory merged commit 748d928 into 5.x Oct 12, 2026
4 checks passed
@markstory
markstory deleted the fix-config-load-exit branch October 12, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configuration load failure in config/bootstrap.php exits with status 0

2 participants