Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Errors Laravel Package

axy/errors

axy/errors is a PHP 8.1+ helper for defining and organizing exception classes. Provides common exception structures, basic error classes, default messages, backtrace truncation, and global options to standardize error handling across projects.

View on GitHub
Deep Wiki
Context7

The error message

The exception classes that inherit from axy\errors\* are able to define the default message. Not to write it every time.

class MyError extends \axy\errors\Logic implements Error
{
    protected $defaultMessage = 'This is default message';
}

throw new MyError(); // This is default message
throw new MyError('message'); // message

The message template

In $defaultMessage can write a message template in which the variables are inserted using {{ var }}. Then, instead of a string you can pass an array of variables.

class QueryError extends \axy\errors\Logic
{
    protected $defaultMessage = 'Error #{{ code }} in query "{{ query }}": {{ error }}';

    public function __construct($query, $error, $code)
    {
        $this->query = $query;
        $this->error = $error;
        $message = [
            'query' => $query,
            'error' => $error,
        ];
        parent::__construct($message, $code);
    }

    final public function getQuery()
    {
        return $this->query;
    }

    final public function getError()
    {
        return $this->error;
    }

    private $query, $error;
}

Use:

class MyDB
{
    public function query($sql) 
    {
        if (!$this->db->query($sql)) {
            throw new QueryError($sql, $this->db->error, $this->db->errno);
        }
    }
}

Do a query to a nonexistent table:

$mydb->query('SELECT * FROM `unknown`');

Output:

QueryError: Error #1146 in query "SELECT * FROM `unknown`": Table 'test.unknown' doesn't exist

If one of the variables is an object then it can be reduced to a string. If it is impossible then reduced to empty string.

If {{ code }} is specified in the template and it is not found in an array used $code of the exception.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle