About Errors

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

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

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);