libgit2/include/git2
Vicent Marti fa59f18d0d Change error handling mechanism once again
Ok, this is the real deal. Hopefully. Here's how it's going to work:

- One main method, called `git__throw`, that sets the error
	code and error message when an error happens.

	This method must be called in every single place where an error
	code was being returned previously, setting an error message
	instead.

	Example, instead of:

		return GIT_EOBJCORRUPTED;

	Use:

		return git__throw(GIT_EOBJCORRUPTED,
			"The object is missing a finalizing line feed");

	And instead of:

		[...] {
			error = GIT_EOBJCORRUPTED;
			goto cleanup;
		}

	Use:

		[...] {
			error = git__throw(GIT_EOBJCORRUPTED, "What an error!");
			goto cleanup;
		}

	The **only** exception to this are the allocation methods, which
	return NULL on failure but already set the message manually.

		/* only place where an error code can be returned directly,
		   because the error message has already been set by the wrapper */
		if (foo == NULL)
			return GIT_ENOMEM;

- One secondary method, called `git__rethrow`, which can be used to
fine-grain an error message and build an error stack.

	Example, instead of:

		if ((error = foobar(baz)) < GIT_SUCCESS)
			return error;

	You can now do:

		if ((error = foobar(baz)) < GIT_SUCCESS)
			return git__rethrow(error, "Failed to do a major operation");

	The return of the `git_lasterror` method will be a string in the
	shape of:

		"Failed to do a major operation. (Failed to do an internal
		operation)"

	E.g.

		"Failed to open the index. (Not enough permissions to access
		'/path/to/index')."

	NOTE: do not abuse this method. Try to write all `git__throw`
	messages in a descriptive manner, to avoid having to rethrow them to
	clarify their meaning.

	This method should only be used in the places where the original
	error message set by a subroutine is not specific enough.

	It is encouraged to continue using this style as much possible to
	enforce error propagation:

		if ((error = foobar(baz)) < GIT_SUCCESS)
			return error; /* `foobar` has set an error message, and
							 we are just propagating it */

The error handling revamp will take place in two phases:

	- Phase 1: Replace all pieces of code that return direct error codes
	with calls to `git__throw`. This can be done semi-automatically
	using `ack` to locate all the error codes that must be replaced.

	- Phase 2: Add some `git__rethrow` calls in those cases where the
	original error messages are not specific enough.

Phase 1 is the main goal. A minor libgit2 release will be shipped once
Phase 1 is ready, and the work will start on gradually improving the
error handling mechanism by refining specific error messages.

OTHER NOTES:

	- When writing error messages, please refrain from using weasel
	words. They add verbosity to the message without giving any real
	information. (<3 Emeric)

	E.g.

		"The reference file appears to be missing a carriage return"
			Nope.

		"The reference file is missing a carriage return"
			Yes.

	- When calling `git__throw`, please try to use more generic error
	codes so we can eventually reduce the list of error codes to
	something more reasonable. Feel free to add new, more generic error
	codes if these are going to replace several of the old ones.

	E.g.

		return GIT_EREFCORRUPTED;

	Can be turned into:

		return git__throw(GIT_EOBJCORRUPTED,
			"The reference is corrupted");
2011-05-09 21:58:02 +03:00
..
blob.h Do not return on void helper methods 2011-03-23 15:44:52 +02:00
commit.h Added git_commit_tree_oid and git_commit_parent_oid. 2011-04-08 03:33:46 +03:00
common.h Change error handling mechanism once again 2011-05-09 21:58:02 +03:00
errors.h errors: Update external API with new git_lasterror 2011-05-09 21:58:02 +03:00
index.h Re-apply missing patches 2011-05-02 01:12:53 +03:00
object.h I broke your bindings 2011-03-20 21:45:11 +02:00
odb_backend.h Remove circular dependency in includes 2011-03-23 20:18:34 +02:00
odb.h odb.h: Fix minor typo 2011-03-23 18:55:44 +02:00
oid.h Add git_oid_shorten (unique OID minimzer) 2011-03-14 23:36:10 +02:00
refs.h Enforce coding conventions in refs.c 2011-03-29 19:58:19 +03:00
repository.h Add two new accessors to the repository 2011-04-09 15:25:24 -07:00
revwalk.h Fix headers for the new Revision Walker 2011-03-16 23:59:09 +02:00
signature.h Rename git_signature_new_now 2011-04-09 15:31:12 -07:00
tag.h Add git_tag_list 2011-04-12 15:55:51 -07:00
thread-utils.h errors: Add error handling function 2011-05-09 21:58:01 +03:00
tree.h Build & write custom trees in memory 2011-04-04 19:25:33 +03:00
types.h Build & write custom trees in memory 2011-04-04 19:25:33 +03:00
zlib.h Move the external includes folder from src to include 2011-03-03 20:23:53 +02:00