4 `BUG`, `die`, `usage`, `error`, and `warning` report errors of
7 - `BUG` is for failed internal assertions that should never happen,
8 i.e. a bug in git itself.
10 - `die` is for fatal application errors. It prints a message to
11 the user and exits with status 128.
13 - `usage` is for errors in command line usage. After printing its
14 message, it exits with status 129. (See also `usage_with_options`
15 in the link:api-parse-options.html[parse-options API].)
17 - `error` is for non-fatal library errors. It prints a message
18 to the user and returns -1 for convenience in signaling the error
21 - `warning` is for reporting situations that probably should not
22 occur but which the user (and Git) can continue to work around
23 without running into too many problems. Like `error`, it
24 returns -1 after reporting the situation to the caller.
26 Customizable error handlers
27 ---------------------------
29 The default behavior of `die` and `error` is to write a message to
30 stderr and then exit or return as appropriate. This behavior can be
31 overridden using `set_die_routine` and `set_error_routine`. For
32 example, "git daemon" uses set_die_routine to write the reason `die`
33 was called to syslog before exiting.
38 Functions return a negative integer on error. Details beyond that
39 vary from function to function:
41 - Some functions return -1 for all errors. Others return a more
42 specific value depending on how the caller might want to react
45 - Some functions report the error to stderr with `error`,
46 while others leave that for the caller to do.
48 - errno is not meaningful on return from most functions (except
49 for thin wrappers for system calls).
51 Check the function's API documentation to be sure.
56 An increasing number of functions take a parameter 'struct strbuf *err'.
57 On error, such functions append a message about what went wrong to the
58 'err' strbuf. The message is meant to be complete enough to be passed
59 to `die` or `error` as-is. For example:
61 if (ref_transaction_commit(transaction, &err))
64 The 'err' parameter will be untouched if no error occurred, so multiple
65 function calls can be chained:
67 t = ref_transaction_begin(&err);
69 ref_transaction_update(t, "HEAD", ..., &err) ||
70 ret_transaction_commit(t, &err))
73 The 'err' parameter must be a pointer to a valid strbuf. To silence
74 a message, pass a strbuf that is explicitly ignored:
76 if (thing_that_can_fail_in_an_ignorable_way(..., &err))
77 /* This failure is okay. */