From 71bf64c1e2c9b783a3603797071a82316e9e2f5f Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Fri, 11 Sep 2026 12:17:15 -0400 Subject: [PATCH] Complete ErrorHandler rollout: wire into all endpoints, fix display_errors gaps, add styled 500 page (#38, #39, #105) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit README documented ErrorHandler.php as a "global error/exception handler", but ErrorHandler::init() had exactly one caller app-wide (api/get_template.php). 13 endpoints never called ini_set('display_errors', 0) at all, relying on the server's global php.ini default, and index.php never registered any handler — a genuine PHP fatal during a page render fell through to PHP's raw default handling with no app-level 500 response, styled or otherwise. Investigating the "13 endpoints" claim turned up that 9 of them (assign_ticket.php, audit_log.php, check_duplicates.php, get_comments.php, get_users.php, notifications.php, saved_filters.php, user_preferences.php, watch_ticket.php) already require api/bootstrap.php as their first statement, which itself calls ini_set('display_errors', 0) — so they were never actually exposed; the static grep just couldn't see through the require. The 3 that were genuinely unprotected (bulk_operation.php, download_attachment.php, health.php) are fixed here. ticket_dependencies.php already has its own complete hand-rolled equivalent (shutdown handler, error handler, exception handler, output-buffer aware) and was deliberately left alone rather than risk double-registering handlers. Rather than duplicate the fix 30+ times, wired ErrorHandler::init() directly into api/bootstrap.php (covering all 9 files above at once) and into each of the other endpoints' own ini_set/error_reporting pair, replacing it in place — additive only: existing try/catch blocks in every endpoint still handle what they already handled identically, this only adds a safety net for genuinely uncaught fatals that fell through everything else. Before doing this app-wide, removed ErrorHandler::init()'s override of PHP's 'error_log' ini setting: it redirected every error_log() call in the request to a fixed /tmp file, which would have silently diverted logs away from wherever the server is actually configured to send them the moment this got wired into more than one endpoint. That override only existed to support getRecentErrors(), which has zero callers app-wide. For index.php (page views, not JSON), added an 'html' response mode to ErrorHandler that renders a new views/error_500.php instead of a JSON body. That view is deliberately self-contained (no layout_header.php, no $GLOBALS/session/DB dependency) since a genuine fatal can happen before config.php finishes loading or mid-session-start. Verified: a real uncaught error with no prior output correctly produces a clean JSON 500 (API mode) or the styled HTML page (page mode) to the client while the full stack trace goes to error_log, not the response; normal (non-fatal) requests through both a bootstrap.php-based endpoint and index.php are byte-for-byte unaffected. Full project phpcs pass is clean. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Lhz7pGMaoTfL5sdYS5XiKv --- api/add_comment.php | 4 ++-- api/bootstrap.php | 4 ++-- api/bulk_operation.php | 3 +++ api/clone_ticket.php | 4 ++-- api/custom_fields.php | 4 ++-- api/delete_attachment.php | 4 ++-- api/delete_comment.php | 4 ++-- api/download_attachment.php | 3 +++ api/export_tickets.php | 4 ++-- api/generate_api_key.php | 4 ++-- api/health.php | 3 +++ api/manage_recurring.php | 4 ++-- api/manage_templates.php | 4 ++-- api/manage_workflows.php | 4 ++-- api/revoke_api_key.php | 4 ++-- api/ticket_comment_api.php | 4 ++-- api/ticket_status_api.php | 4 ++-- api/tickets_api.php | 4 ++-- api/update_comment.php | 4 ++-- api/update_ticket.php | 4 ++-- api/upload_attachment.php | 4 ++-- api/user_avatar.php | 4 ++-- create_ticket_api.php | 4 ++-- helpers/ErrorHandler.php | 31 +++++++++++++++++++++++++----- index.php | 7 +++++++ views/error_500.php | 38 +++++++++++++++++++++++++++++++++++++ 26 files changed, 120 insertions(+), 45 deletions(-) create mode 100644 views/error_500.php diff --git a/api/add_comment.php b/api/add_comment.php index 6fecce9..0a17e8b 100644 --- a/api/add_comment.php +++ b/api/add_comment.php @@ -1,8 +1,8 @@ + + + + + + 500 — Something Went Wrong + + + + +
+ +
[ 500 ] SOMETHING WENT WRONG
+
+

+ An unexpected error occurred. It's been logged; please try again shortly. +

+ ← Dashboard +
+
+ +