Skip to content

Commit db0c664

Browse files
authored
Merge pull request libgit2#4773 from RandomSort/giterr
Document giterr_last() use only after error. libgit2#4772
2 parents df2f276 + c0b2e52 commit db0c664

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

docs/error-handling.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ The public error API
117117
the last error. This may return NULL if no error has occurred.
118118
Otherwise this should return a `git_error` object indicating the class
119119
of error and the error message that was generated by the library.
120+
Do not use this function unless the prior call to a libgit2 API
121+
returned an error, as it can otherwise give misleading results.
122+
libgit2's error strings are not cleared aggressively,
123+
and this function may return an error string that reflects a prior error,
124+
possibly even reflecting internal state.
120125
121126
The last error is stored in thread-local storage when libgit2 is
122127
compiled with thread support, so you do not have to worry about another

include/git2/errors.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ typedef enum {
109109

110110
/**
111111
* Return the last `git_error` object that was generated for the
112-
* current thread or NULL if no error has occurred.
112+
* current thread.
113+
*
114+
* The default behaviour of this function is to return NULL if no previous error has occurred.
115+
* However, libgit2's error strings are not cleared aggressively, so a prior
116+
* (unrelated) error may be returned. This can be avoided by only calling
117+
* this function if the prior call to a libgit2 API returned an error.
113118
*
114119
* @return A git_error object.
115120
*/

0 commit comments

Comments
 (0)