Error module
Introduction
The error module is intended as a tool to help uniform error handling in modules. The object of this class is to avoid returning arrays when errors are encountered.
Setting an error
When something goes wrong in your module you can set the error like this
$this -> error -> set('Oops, something went wrong!', $logging, $fatal);
return $this -> error -> message();
When used with the base module and un-customised tell(), gc() and pgmsg() this will send a tell to the person invoking the command that the module has had an error and the message you defined.
If $logging == true then an entry will be logged to the console (via $this -> bot -> log()) If $fatal == true then the bot will halt execution with an error code of 1. Do NOT use this unless the error is such that the bot should stop execution.
Checking if an error has occured
You can check if an error has been raised by comparing the error objects status to a boolean.
if($this->error->status() === true)
{
//An error has occured
}
Resetting the error object
This is particularly useful to do before the command is parsed so that a stale error does not affect the command
$this -> error -> reset();
If you do not reset the error a previous error will be reported even if the command was executed successfully this time.
Getting the error message
If you just want to get the message that was defined when raising the error without the color formatting of $this -> error -> message() you can call the get-function like this
$message = $this -> error -> get();
If no errors have been raised this will return an empty string.