NAME

DBIx::Class::Async::Exception::Factory - Translate raw DBIx::Class errors into typed exception objects

VERSION

Version 0.63

SYNOPSIS

use DBIx::Class::Async::Exception::Factory;
use Try::Tiny;

try {
    # ... async DBIC operation ...
}
catch {
    # Translates the raw string error into the right typed subclass,
    # then re-throws it.
    DBIx::Class::Async::Exception::Factory->throw_from_dbic_error(
        error        => $_,
        schema       => $self->schema,
        result_class => $result_class,
        operation    => $operation,
    );
};

DESCRIPTION

This factory inspects raw DBIx::Class exception strings, matches them against known error patterns, and throws the appropriate DBIx::Class::Async::Exception subclass. If no pattern matches, it wraps the error in the base DBIx::Class::Async::Exception so callers always receive a structured object rather than a plain string.

METHODS

throw_from_dbic_error

DBIx::Class::Async::Exception::Factory->throw_from_dbic_error(
    error        => $raw_error_string,   # required
    schema       => $schema,             # optional, enables relationship detection
    result_class => $result_class,       # optional, e.g. 'My::Schema::Result::Foo'
    operation    => $operation,          # optional, e.g. 'update_or_create'
);

Matches error against known DBIC error patterns and throws the appropriate DBIx::Class::Async::Exception subclass. If no pattern matches, wraps the raw string in the base DBIx::Class::Async::Exception and throws that.

Always throws -- never returns.

make_from_dbic_error

my $exception = DBIx::Class::Async::Exception::Factory->make_from_dbic_error(%args);

Like "throw_from_dbic_error" but returns the exception object instead of throwing it. Useful when you need to attach the exception to a failed Future rather than die-ing directly.

validate_or_fail

my $exception = DBIx::Class::Async::Exception::Factory->validate_or_fail(
    args         => \%hashref,       # the create/update hashref
    schema       => $schema,         # DBIx::Class::Schema instance or class name
    result_class => $result_class,   # e.g. 'My::Schema::Result::Operation'
    operation    => $operation,      # e.g. 'update_or_create'
);
return Future->fail($exception) if $exception;

Pre-flight check intended for use in _call_worker before dispatching to the worker process. Inspects args for relationship keys with undef values and returns a DBIx::Class::Async::Exception::RelationshipAsColumn object if one is found, or undef if the args look clean.

Returns an exception object rather than throwing, so the caller can decide how to surface it -- typically as Future->fail($exception) to keep error handling consistent with the rest of the async pipeline.

ADDING NEW PATTERNS

Add a new entry to the @PATTERNS array:

{
    class => 'DBIx::Class::Async::Exception::YourSubclass',  # or base class
    match => qr/your regex with (\w+) captures/,
    build => sub {
        my (%p) = @_;
        # $p{error}        -- raw error string
        # $p{captures}     -- arrayref of regex captures
        # $p{schema}       -- schema object (may be undef)
        # $p{result_class} -- e.g. 'My::Schema::Result::Foo' (may be undef)
        # $p{operation}    -- e.g. 'create' (may be undef)
        #
        # Return a flat %args hash to pass to the exception class constructor.
        # Return an empty list () to skip this pattern and try the next one.
        return (
            message        => _fmt_message("Your friendly message"),
            hint           => "What the user should do.",
            original_error => $p{error},
        );
    },
},

AUTHOR

Mohammad Sajid Anwar, <mohammad.anwar at yahoo.com>

REPOSITORY

https://github.com/manwar/DBIx-Class-Async

BUGS

Please report any bugs or feature requests through the web interface at https://github.com/manwar/DBIx-Class-Async/issues. I will be notified and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc DBIx::Class::Async::Exception::Factory

You can also look for information at:

LICENSE AND COPYRIGHT

Copyright (C) 2026 Mohammad Sajid Anwar.

This program is free software; you can redistribute it and / or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: http://www.perlfoundation.org/artistic_license_2_0 Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License.By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. If your Modified Version has been derived from a Modified Version made by someone other than you,you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement,then this Artistic License to you shall terminate on the date that such litigation is filed. Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.