NAME

Git::Background::Exception - exception class for Git::Background

VERSION

Version 0.001

SYNOPSIS

A new error object may be generated and thrown as follows:

die Git::Background::Exception->new({
    stdout => $stdout,
    stderr => $stderr,
    exit_code => $exit_code,
});

DESCRIPTION

This object is thrown by Git::Background if the Git process returned a non-zero return code.

The object stringifies to either the output printed to STDERR by Git or, if none was printed, a generic error message containing the exit code of Git.

USAGE

new( ARGS )

Constructor for this class.

exit_code (required)

The exit code returned by Git.

stderr (required)

An array reference containing all the output lines printed to STDERR by Git.

stdout (required)

An array reference containing all the output lines printed to STDOUT by Git.

exit_code

Returns the exit code returned by Git. This is the reason the exception was thrown.

stderr

Returns a list of all the output lines printed to standard error by Git.

my @stderr = $e->stderr;

stdout

Returns a list of all the output lines printed to standard output by Git.

my @stdout = $e->stdout;

EXAMPLES

Example 1 Catch exception with Feature::Compat::Try

use 5.014;
use strict;
use warnings;

use lib qw(.. .. lib);

use Feature::Compat::Try;
use Scalar::Util qw(blessed);
use Git::Background;

my $git = Git::Background->new;
try {
    $git->run('--invalid-arg')->get;
}
catch ($e) {
    die $e if !blessed $e || !$e->isa('Git::Background::Exception');

    my $exit_code = $e->exit_code;
    my $stderr    = join "\n", $e->stderr;
    warn "Git exited with exit code $exit_code\n$stderr\n";
}

Example 2 Catch exception with eval

use 5.006;
use strict;
use warnings;

use lib qw(.. .. lib);

use Scalar::Util qw(blessed);
use Git::Background;

my $git = Git::Background->new;

if ( !eval { $git->run('--invalid-arg')->get; 1; } ) {
    my $e = $@;
    die $e if !blessed $e || !$e->isa('Git::Background::Exception');

    my $exit_code = $e->exit_code;
    my $stderr    = join "\n", $e->stderr;
    warn "Git exited with exit code $exit_code\n$stderr\n";
}

SEE ALSO

Git::Wrapper::Exception

SUPPORT

Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker at https://github.com/skirmess/Git-Background/issues. You will be notified automatically of any progress on your issue.

Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

https://github.com/skirmess/Git-Background

git clone https://github.com/skirmess/Git-Background.git

AUTHOR

Sven Kirmess <sven.kirmess@kzone.ch>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2021 by Sven Kirmess.

This is free software, licensed under:

The (two-clause) FreeBSD License