NAME

Git::Libgit2::Error - Wraps git_error_last() into a Perl structure

VERSION

version 0.004

SYNOPSIS

my $rc = git_repository_open(\my $repo, $path);
if ($rc < 0) {
  die Git::Libgit2::Error->last($rc);   # stringifies
}

DESCRIPTION

Error object wrapping libgit2's thread-local git_error_last. Provides code, klass, and message accessors. Stringifies to a human-readable message via overload. Used by Git::Native to construct typed exceptions.

last

die Git::Libgit2::Error->last($rc);

Construct an error object from libgit2's current thread-local error state (git_error_last). $rc is the return code that triggered the lookup and defaults to -1. Always returns a blessed object, even when libgit2 reports no error — message is then <no error>.

code

my $rc = $error->code;

The libgit2 return code that triggered this error.

klass

my $klass = $error->klass;

The libgit2 error class (git_error_t category). Currently always 0 — the klass field is not yet decoded from the git_error struct.

message

my $msg = $error->message;

The human-readable libgit2 error message, or <no error> when libgit2 reported none.

stringify

my $str = $error->stringify;
print "$error";   # same, via overloaded stringification

Format the error as "libgit2 error CODE (klass KLASS): MESSAGE". Also wired up as the "" overload, so the object stringifies to this in interpolation and when thrown.

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/p5-git-libgit2/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.