\Cake\ConsoleConsoleErrorHandler

Error Handler for Cake console. Does simple printing of the exception that occurred and the stack trace of the error.

Subclasses are required to implement the template methods to handle displaying the errors in their environment.

Summary

Methods
Properties
Constants
register()
handleError()
wrapAndHandleException()
handleException()
handleFatalError()
increaseMemoryLimit()
mapErrorCode()
__construct()
No public properties found
No constants found
_displayError()
_displayException()
_stop()
_logError()
_logException()
_requestContext()
_getMessage()
$_options
$_handled
$_stderr
N/A
No private methods found
No private properties found
N/A

Properties

$_options

$_options : array

Options for this instance.

Type

array

$_handled

$_handled : boolean

Type

boolean

Methods

register()

register() : void

Register the error and exception handlers.

handleError()

handleError(integer  $code, string  $description, string|null  $file = null, integer|null  $line = null, array|null  $context = null) : boolean

Set as the default error handler by CakePHP.

Use config/error.php to customize or replace this error handler. This function will use Debugger to display errors when debug > 0. And will log errors to Log, when debug == 0.

You can use the 'errorLevel' option to set what type of errors will be handled. Stack traces for errors can be enabled with the 'trace' option.

Parameters

integer $code

Code of error

string $description

Error description

string|null $file

File on which error occurred

integer|null $line

Line that triggered the error

array|null $context

Context

Returns

boolean —

True if error was handled

wrapAndHandleException()

wrapAndHandleException(\Exception|\Error  $exception) : void

Checks the passed exception type. If it is an instance of `Error` then, it wraps the passed object inside another Exception object for backwards compatibility purposes.

Parameters

\Exception|\Error $exception

The exception to handle

handleException()

handleException(\Exception  $exception) : void

Handle errors in the console environment. Writes errors to stderr, and logs messages if Configure::read('debug') is false.

Uses a template method provided by subclasses to display errors in an environment appropriate way.

Parameters

\Exception $exception

Exception instance.

Throws

\Exception

When renderer class not found

handleFatalError()

handleFatalError(integer  $code, string  $description, string  $file, integer  $line) : boolean

Display/Log a fatal error.

Parameters

integer $code

Code of error

string $description

Error description

string $file

File on which error occurred

integer $line

Line that triggered the error

Returns

boolean

increaseMemoryLimit()

increaseMemoryLimit(integer  $additionalKb) : void

Increases the PHP "memory_limit" ini setting by the specified amount in kilobytes

Parameters

integer $additionalKb

Number in kilobytes

mapErrorCode()

mapErrorCode(integer  $code) : array

Map an error code into an Error word, and log location.

Parameters

integer $code

Error code to map

Returns

array —

Array of error word, and log location.

__construct()

__construct(array  $options = array()) 

Constructor

Parameters

array $options

Options for the error handler.

_displayError()

_displayError(array  $error, boolean  $debug) : void

Prints an error to stderr.

Template method of BaseErrorHandler.

Parameters

array $error

An array of error data.

boolean $debug

Whether or not the app is in debug mode.

_displayException()

_displayException(\Exception  $exception) : void

Prints an exception to stderr.

Subclasses should implement this method to display an uncaught exception as desired for the runtime they operate in.

Parameters

\Exception $exception

The exception to handle

_stop()

_stop(integer  $code) : void

Stop the execution and set the exit code for the process.

Implemented in subclasses that need it.

Parameters

integer $code

The exit code.

_logError()

_logError(string  $level, array  $data) : boolean

Log an error.

Parameters

string $level

The level name of the log.

array $data

Array of error data.

Returns

boolean

_logException()

_logException(\Exception  $exception) : boolean

Handles exception logging

Parameters

\Exception $exception

Exception instance.

Returns

boolean

_requestContext()

_requestContext(\Cake\Http\ServerRequest  $request) : string

Get the request context for an error/exception trace.

Parameters

\Cake\Http\ServerRequest $request

The request to read from.

Returns

string

_getMessage()

_getMessage(\Exception  $exception) : string

Generates a formatted error message

Parameters

\Exception $exception

Exception instance

Returns

string —

Formatted message