summaryrefslogtreecommitdiff
path: root/src/errors.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-03-09 19:55:50 +0100
committerVicent Martí <tanoku@gmail.com>2012-03-09 20:09:22 +0100
commitdda708e78f3c3f43d814d46c29ab9f2b9d47ed5c (patch)
tree60a6e01583c15209a42740a46e182ac7cbc893de /src/errors.c
parent6af24ce31f43c3621f11720704a078058665bc3f (diff)
downloadlibgit2-dda708e78f3c3f43d814d46c29ab9f2b9d47ed5c.tar.gz
error-handling: On-disk config file backend
Includes: - Proper error reporting when encountering syntax errors in a config file (file, line number, column). - Rewritten `config_write`, now with 99% less goto-spaghetti - Error state in `git_filebuf`: filebuf write functions no longer need to be checked for error returns. If any of the writes performed on a buffer fail, the last call to `git_filebuf_commit` or `git_filebuf_hash` will fail accordingly and set the appropiate error message. Baller!
Diffstat (limited to 'src/errors.c')
-rw-r--r--src/errors.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/errors.c b/src/errors.c
index c25fa7519..6fb7777f0 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -122,25 +122,28 @@ void giterr_set(int error_class, const char *string, ...)
{
char error_str[1024];
va_list arglist;
- git_error *error;
- const char *oserr =
- (error_class == GITERR_OS && errno != 0) ? strerror(errno) : NULL;
-
- error = &GIT_GLOBAL->error_t;
- free(error->message);
va_start(arglist, string);
p_vsnprintf(error_str, sizeof(error_str), string, arglist);
va_end(arglist);
/* automatically suffix strerror(errno) for GITERR_OS errors */
- if (oserr != NULL) {
+ if (error_class == GITERR_OS) {
strncat(error_str, ": ", sizeof(error_str));
- strncat(error_str, oserr, sizeof(error_str));
+ strncat(error_str, strerror(errno), sizeof(error_str));
errno = 0;
}
- error->message = git__strdup(error_str);
+ giterr_set_str(error_class, error_str);
+}
+
+void giterr_set_str(int error_class, const char *string)
+{
+ git_error *error = &GIT_GLOBAL->error_t;
+
+ free(error->message);
+
+ error->message = git__strdup(string);
error->klass = error_class;
if (error->message == NULL) {
@@ -151,6 +154,13 @@ void giterr_set(int error_class, const char *string, ...)
GIT_GLOBAL->last_error = error;
}
+void giterr_set_regex(const regex_t *regex, int error_code)
+{
+ char error_buf[1024];
+ regerror(error_code, regex, error_buf, sizeof(error_buf));
+ giterr_set_str(GITERR_REGEX, error_buf);
+}
+
void giterr_clear(void)
{
GIT_GLOBAL->last_error = NULL;