Commit f78f6bd5 by Edward Thomson

error functions: return an int

Stop returning a void for functions, future-proofing them to allow them
to fail.
parent 4b331f02
...@@ -143,8 +143,9 @@ GIT_EXTERN(void) git_error_clear(void); ...@@ -143,8 +143,9 @@ GIT_EXTERN(void) git_error_clear(void);
* @param error_class One of the `git_error_t` enum above describing the * @param error_class One of the `git_error_t` enum above describing the
* general subsystem that is responsible for the error. * general subsystem that is responsible for the error.
* @param string The formatted error message to keep * @param string The formatted error message to keep
* @return 0 on success or -1 on failure
*/ */
GIT_EXTERN(void) git_error_set_str(int error_class, const char *string); GIT_EXTERN(int) git_error_set_str(int error_class, const char *string);
/** /**
* Set the error message to a special value for memory allocation failure. * Set the error message to a special value for memory allocation failure.
......
...@@ -95,19 +95,25 @@ void git_error_vset(int error_class, const char *fmt, va_list ap) ...@@ -95,19 +95,25 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
set_error_from_buffer(error_class); set_error_from_buffer(error_class);
} }
void git_error_set_str(int error_class, const char *string) int git_error_set_str(int error_class, const char *string)
{ {
git_buf *buf = &GIT_GLOBAL->error_buf; git_buf *buf = &GIT_GLOBAL->error_buf;
assert(string); assert(string);
if (!string) if (!string) {
return; git_error_set(GIT_ERROR_INVALID, "unspecified caller error");
return -1;
}
git_buf_clear(buf); git_buf_clear(buf);
git_buf_puts(buf, string); git_buf_puts(buf, string);
if (!git_buf_oom(buf))
if (git_buf_oom(buf))
return -1;
set_error_from_buffer(error_class); set_error_from_buffer(error_class);
return 0;
} }
void git_error_clear(void) void git_error_clear(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment