Search by

raxos / error

basmilius

Error handling related primitives.

3.2.0 2026-10-02 17:09 UTC

This package is auto-updated.

Last update: 2026-10-03 12:05:57 UTC


README

Bas Milius

Raxos Error

A common exception base with machine-readable error names, descriptions and numeric IDs.

Documentation | Packagist | Raxos

  • Exceptions implement the shared ExceptionInterface and serialize to JSON.
  • ExceptionId derives repeatable IDs from a class or method name.
  • A shared InvalidArgumentException for invalid inputs.

Installation

Requires PHP 8.5 or later. Composer checks the remaining package and extension dependencies declared in composer.json.

composer require "raxos/error:^3.2"

Usage

<?php
declare(strict_types=1);

use Raxos\Error\Exception;

require __DIR__ . '/vendor/autoload.php';

final class ProductNotFound extends Exception
{
    public function __construct(int $id)
    {
        parent::__construct(
            error: 'product_not_found',
            errorDescription: "Product {$id} does not exist."
        );
    }
}

echo json_encode(new ProductNotFound(42));

The JSON representation contains code, error and error_description. If no code is supplied, the base exception derives one from the concrete exception class. A previous exception can be passed through the constructor.

Documentation

Testing

Run this library's Pest suite from the Raxos workspace:

git clone --recurse-submodules https://github.com/basmilius/raxos.git
cd raxos
composer install
vendor/bin/pest --testsuite=error

See Testing Raxos for PHP extensions, integration services and coverage commands. The library's Tests workflow also runs in GitHub Actions.

License

MIT. Copyright (c) 2017 - present Bas Milius.