Skip to content

About Errors

Daniel Pimley edited this page Oct 4, 2023 · 21 revisions

Chyrp Lite offers developers a few ways to handle and report errors. The level of error reporting and the verbosity of output depends on whether debug mode is enabled.

Reporting Errors

Whenever possible, errors should be reported using the functions provided by Chyrp Lite; this ensures consistent presentation to visitors and minimum disruption if the error is recoverable. For unanticipated errors, Chyrp Lite's environment also provides default Error and Exception handlers.

Error Functions

The following functions are available for reporting errors:

error()

The error() function is the backbone of error handling in Chyrp Lite. It will be called automatically if an error or exception is encountered, but it can also be called directly and supplied a HTTP error status code to be sent to the user-agent. This function will report the error on a pretty error page and then end execution immediately, so it’s best avoided for recoverable errors.

Flash::warning()

For recoverable errors you can use the Flash class to display a warning to the user. Chyrp Lite generally tries to use flashes to report errors encountered on the visitor-facing blog pages. You’ll see Flash being used a lot in MainController, for example.

show_403()

This helper function is a shortcut to return error 403: Forbidden. If the visitor is accessing a blog page, this function will attempt to display the error message in a template provided by the current theme.

show_404()

This helper function is a shortcut to return error 404: Not Found. If the visitor is accessing a blog page, this function will attempt to display the error message in a template provided by the current theme.

Analysing Errors

In debug mode, the following behaviours support analysis of errors:

Backtraces

A backtrace will be captured and enumerated on the pretty error page displayed by error().

Logging

Failure states will be logged to the file error_log.txt in the install directory.

Triggering Errors

In production mode, errors of level E_NOTICE and E_USER_NOTICE will be ignored, meaning that you can use the following code to trigger errors that are reported only in debug mode:

trigger_error("Foobar!", E_USER_NOTICE);
Clone this wiki locally