diff options
author | Petr Baudis <pasky@suse.cz> | 2006-06-24 04:34:42 +0200 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-07-02 17:14:40 -0700 |
commit | 97b16c067492506287a6f474e79ef6cbe0a30e49 (patch) | |
tree | 4966560d51c8e23cc3c9467c322d273fae945905 /perl/Git.xs | |
parent | 5c4082fd687bd0784d3a4d96550e8afab332b63a (diff) | |
download | git-97b16c067492506287a6f474e79ef6cbe0a30e49.tar.gz |
Git.pm: Better error handling
So far, errors just killed the whole program and in case of an error
inside of libgit it would be totally uncatchable. This patch makes
Git.pm throw standard Perl exceptions instead. In the future we might
subclass Error to Git::Error or something but for now Error::Simple
is more than enough.
Signed-off-by: Petr Baudis <pasky@suse.cz>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'perl/Git.xs')
-rw-r--r-- | perl/Git.xs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/perl/Git.xs b/perl/Git.xs index d4608eb1cb..9d247b7130 100644 --- a/perl/Git.xs +++ b/perl/Git.xs @@ -8,6 +8,8 @@ #include "../cache.h" #include "../exec_cmd.h" +#define die perlyshadow_die__ + /* XS and Perl interface */ #include "EXTERN.h" #include "perl.h" @@ -15,11 +17,48 @@ #include "ppport.h" +#undef die + + +static char * +report_xs(const char *prefix, const char *err, va_list params) +{ + static char buf[4096]; + strcpy(buf, prefix); + vsnprintf(buf + strlen(prefix), 4096 - strlen(prefix), err, params); + return buf; +} + +void +die_xs(const char *err, va_list params) +{ + char *str; + str = report_xs("fatal: ", err, params); + croak(str); +} + +int +error_xs(const char *err, va_list params) +{ + char *str; + str = report_xs("error: ", err, params); + warn(str); + return -1; +} + MODULE = Git PACKAGE = Git PROTOTYPES: DISABLE + +BOOT: +{ + set_error_routine(error_xs); + set_die_routine(die_xs); +} + + # /* TODO: xs_call_gate(). See Git.pm. */ |