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.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui