]>
Commit | Line | Data |
---|---|---|
02f9e637 | 1 | /* |
5e0de328 | 2 | * Copyright (C) 2009-2012 the libgit2 contributors |
02f9e637 | 3 | * |
bb742ede VM |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
02f9e637 | 6 | */ |
ae234862 | 7 | #include "common.h" |
a15c550d | 8 | #include "global.h" |
02f9e637 VM |
9 | #include <stdarg.h> |
10 | ||
ae234862 AE |
11 | static struct { |
12 | int num; | |
13 | const char *str; | |
14 | } error_codes[] = { | |
a8bfce69 VM |
15 | {GIT_ERROR, "Unspecified error"}, |
16 | {GIT_ENOTOID, "Input was not a properly formatted Git object id."}, | |
17 | {GIT_ENOTFOUND, "Object does not exist in the scope searched."}, | |
18 | {GIT_ENOMEM, "Not enough space available."}, | |
19 | {GIT_EOSERR, "Consult the OS error information."}, | |
20 | {GIT_EOBJTYPE, "The specified object is of invalid type"}, | |
21 | {GIT_EOBJCORRUPTED, "The specified object has its data corrupted"}, | |
22 | {GIT_ENOTAREPO, "The specified repository is invalid"}, | |
05314b5b | 23 | {GIT_EINVALIDTYPE, "The object or config variable type is invalid or doesn't match"}, |
a8bfce69 VM |
24 | {GIT_EMISSINGOBJDATA, "The object cannot be written that because it's missing internal data"}, |
25 | {GIT_EPACKCORRUPTED, "The packfile for the ODB is corrupted"}, | |
26 | {GIT_EFLOCKFAIL, "Failed to adquire or release a file lock"}, | |
27 | {GIT_EZLIB, "The Z library failed to inflate/deflate an object's data"}, | |
28 | {GIT_EBUSY, "The queried object is currently busy"}, | |
f2c24713 | 29 | {GIT_EINVALIDPATH, "The path is invalid"}, |
9282e921 | 30 | {GIT_EBAREINDEX, "The index file is not backed up by an existing repository"}, |
31 | {GIT_EINVALIDREFNAME, "The name of the reference is not valid"}, | |
32 | {GIT_EREFCORRUPTED, "The specified reference has its data corrupted"}, | |
33 | {GIT_ETOONESTEDSYMREF, "The specified symbolic reference is too deeply nested"}, | |
c836c332 VM |
34 | {GIT_EPACKEDREFSCORRUPTED, "The pack-refs file is either corrupted of its format is not currently supported"}, |
35 | {GIT_EINVALIDPATH, "The path is invalid" }, | |
6a0895ad | 36 | {GIT_EREVWALKOVER, "The revision walker is empty; there are no more commits left to iterate"}, |
72a3fe42 | 37 | {GIT_EINVALIDREFSTATE, "The state of the reference is not valid"}, |
baad182c | 38 | {GIT_ENOTIMPLEMENTED, "This feature has not been implemented yet"}, |
c6e65aca VM |
39 | {GIT_EEXISTS, "A reference with this name already exists"}, |
40 | {GIT_EOVERFLOW, "The given integer literal is too large to be parsed"}, | |
41 | {GIT_ENOTNUM, "The given literal is not a valid number"}, | |
53c0bd81 | 42 | {GIT_EAMBIGUOUSOIDPREFIX, "The given oid prefix is ambiguous"}, |
ae234862 AE |
43 | }; |
44 | ||
45 | const char *git_strerror(int num) | |
46 | { | |
0ef9d2aa | 47 | size_t i; |
7dd8a9f7 SP |
48 | |
49 | if (num == GIT_EOSERR) | |
50 | return strerror(errno); | |
ae234862 AE |
51 | for (i = 0; i < ARRAY_SIZE(error_codes); i++) |
52 | if (num == error_codes[i].num) | |
53 | return error_codes[i].str; | |
54 | ||
55 | return "Unknown error"; | |
56 | } | |
f4a936b5 | 57 | |
a15c550d VM |
58 | #define ERROR_MAX_LEN 1024 |
59 | ||
d7f0abab | 60 | void git___rethrow(const char *msg, ...) |
fa59f18d | 61 | { |
a15c550d VM |
62 | char new_error[ERROR_MAX_LEN]; |
63 | char *last_error; | |
fa59f18d VM |
64 | char *old_error = NULL; |
65 | ||
66 | va_list va; | |
67 | ||
a15c550d VM |
68 | last_error = GIT_GLOBAL->error.last; |
69 | ||
fa59f18d | 70 | va_start(va, msg); |
a15c550d | 71 | vsnprintf(new_error, ERROR_MAX_LEN, msg, va); |
fa59f18d VM |
72 | va_end(va); |
73 | ||
a15c550d VM |
74 | old_error = git__strdup(last_error); |
75 | ||
76 | snprintf(last_error, ERROR_MAX_LEN, "%s \n - %s", new_error, old_error); | |
77 | ||
3286c408 | 78 | git__free(old_error); |
fa59f18d VM |
79 | } |
80 | ||
d7f0abab | 81 | void git___throw(const char *msg, ...) |
02f9e637 VM |
82 | { |
83 | va_list va; | |
84 | ||
85 | va_start(va, msg); | |
a15c550d | 86 | vsnprintf(GIT_GLOBAL->error.last, ERROR_MAX_LEN, msg, va); |
02f9e637 | 87 | va_end(va); |
02f9e637 | 88 | } |
5eb0fab8 VM |
89 | |
90 | const char *git_lasterror(void) | |
91 | { | |
a15c550d VM |
92 | char *last_error = GIT_GLOBAL->error.last; |
93 | ||
94 | if (!last_error[0]) | |
ab7941b5 VM |
95 | return NULL; |
96 | ||
a15c550d | 97 | return last_error; |
5eb0fab8 VM |
98 | } |
99 | ||
ab7941b5 VM |
100 | void git_clearerror(void) |
101 | { | |
a15c550d VM |
102 | char *last_error = GIT_GLOBAL->error.last; |
103 | last_error[0] = '\0'; | |
ab7941b5 | 104 | } |