git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lea Wiemann <lewiemann@gmail.com>
To: Lea Wiemann <lewiemann@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/3 v2] add new Perl API: Git::Repo, Git::Commit, Git::Tag, and Git::RepoRoot
Date: Tue, 19 Aug 2008 15:51:03 +0200	[thread overview]
Message-ID: <48AACFC7.6070806@gmail.com> (raw)
In-Reply-To: <1219088389-14828-2-git-send-email-LeWiemann@gmail.com>

Since I didn't mention it: The patch series applies on next.


Lea Wiemann wrote:
> +Git::Repo - Read-only access to the Git repositories.
> +
> +Error handling is simple: On a consistent repository, the Perl
> +interface will never die.  You can use the get_sha1 method to resolve
> +arbitrary object names or check the existence of SHA1 hashes; get_sha1
> +will return undef if the object does not exist in the repository.  Any
> +SHA1 that is returned by get_sha1 can be safely passed to the other
> +Git::Repo methods.

Here's some elaboration on the rationale behind the error handling.  As
a reminder, what we do is force developers to resolve object identifiers
(such as HEAD^) into SHA1s first, rather than allowing them to pass in
arbitrary object identifiers into functions.  Here's why:

a) There's really just one point where errors can occur: at the input
boundary (like the command line).  Hence, you usually need one to three
get_sha1 calls to resolve your input object names, and the rest of your
program will be error-handling free with regard to Git::Repo (that is,
if it dies it's either a bug or an error in the repository structure).

On the other hand, if you don't have such an explicit error-checking
boundary at the beginning of your program (where you resolve all
identifiers), you basically allow invalid object identifiers to "creep"
into your code.  For instance, gitweb oftentimes would have statements
like "or die 'ls-tree failed'" or "or die 'commit not found'" deep
inside a function -- in some cases, I found out that these failures
*could* not even happen since the objects were guaranteed to exist by
earlier calls (and hence it was basically dead code); and in many cases
the error messages were simply non-descript -- which brings me to the
next point:

b) Error reporting is really hard to implement: For instance, if
diff-tree returns non-zero, then unless you scrape its STDERR, you can't
tell which of the two to-be-diffed objects didn't exist (or had the
wrong type), and hence you're oftentimes stuck with a generic 'diff-tree
failed' message.  In other words, if a simple diff-tree call goes wrong,
there are three possible causes: (1) The left object is invalid, (2) the
right object is invalid, (3) something fatal happened (bug or repository
breakage).  Distinguishing these cases is hard, and moving the
object-resolving code to the beginning of the API user's program means
that diff-tree failure can only indicate case (3).

c) The error messages you could get from an API are not usually what you
want anyway.  So if you write

     my $diff = diff_tree($obj_identifier_1, $obj_identifier_2)

and expect it to die with a descriptive error message if one of the two
identifiers doesn't point to a valid tree object, the best your error
message can possibly be is "git diff-tree: HEAD^:foo/bar is not a valid
tree object".  Which leaves users puzzled because (1) they didn't call
diff-tree, and (2) the program might have constructed the
"HEAD^:foo/bar" string, and they only passed in parts of it, so it's not
clear to them where "HEAD^:foo/bar" comes from.

d) Last but not least, using exceptions to communicate errors is against
Perl coding conventions -- I would even have to look up the syntax to
check for a specific exception type after an 'eval' block, because I
simply never needed it.

So I think those four reasons really prevail over the extra work of
having to make 1-3 get_sha1 calls at the beginning of your program (and
providing proper error messages if they fail).

  parent reply	other threads:[~2008-08-19 13:52 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-11  1:06 [PATCH 0/3] Git::Repo API and gitweb caching Lea Wiemann
2008-07-11  1:10 ` [PATCH 1/3 v9] gitweb: add test suite with Test::WWW::Mechanize::CGI Lea Wiemann
2008-07-11  1:11 ` [PATCH 2/3] add new Git::Repo API Lea Wiemann
2008-07-13 21:38   ` Junio C Hamano
2008-07-14  1:04     ` Lea Wiemann
2008-07-13 23:28   ` Jakub Narebski
2008-07-14  2:29     ` Lea Wiemann
2008-07-14  1:40   ` Petr Baudis
2008-07-14 22:19     ` Lea Wiemann
2008-07-18 16:48       ` Petr Baudis
2008-07-18 17:05         ` Jakub Narebski
2008-07-18 17:17           ` Petr Baudis
2008-07-18 18:09         ` Lea Wiemann
2008-07-18 18:19           ` Petr Baudis
2008-07-18 18:23           ` Johannes Schindelin
2008-07-19 20:54         ` Statictics on Git.pm usage in git commands (was: [PATCH 2/3] add new Git::Repo API) Jakub Narebski
2008-07-19 21:14           ` Petr Baudis
2008-07-20  0:16             ` Jakub Narebski
2008-07-20 21:38               ` Petr Baudis
2008-07-20 10:38           ` Johannes Schindelin
2008-07-20 10:49             ` Petr Baudis
2008-07-20 12:33               ` Johannes Schindelin
2008-07-20 12:58                 ` Petr Baudis
2008-07-20 13:21                   ` Johannes Schindelin
2008-07-14 23:41     ` [PATCH 2/3] add new Git::Repo API Jakub Narebski
2008-07-15  0:11       ` Lea Wiemann
2008-07-18 16:54       ` Petr Baudis
2008-07-19  0:03         ` Jakub Narebski
2008-07-19 19:07         ` Jakub Narebski
2008-07-20 21:36           ` Petr Baudis
2008-07-20 21:50             ` Jakub Narebski
2008-07-16 18:21   ` Jakub Narebski
2008-07-16 20:32     ` Lea Wiemann
2008-07-17 23:49       ` Jakub Narebski
2008-07-18 13:40         ` Lea Wiemann
2008-07-18 15:35           ` Jakub Narebski
2008-07-18 16:51             ` Lea Wiemann
2008-07-11  1:11 ` [PATCH 3/3] gitweb: use new Git::Repo API, and add optional caching Lea Wiemann
2008-07-14 21:23   ` Jakub Narebski
2008-07-14 23:03     ` Lea Wiemann
2008-07-14 23:14       ` Jakub Narebski
2008-07-14 23:56         ` Lea Wiemann
2008-07-15  0:52           ` Jakub Narebski
2008-07-15  1:16             ` Lea Wiemann
2008-07-15  1:28               ` Johannes Schindelin
2008-07-15  1:44                 ` J.H.
2008-07-15  1:50                 ` Lea Wiemann
2008-07-15  2:03                   ` J.H.
2008-07-11  1:21 ` [PATCH 0/3] Git::Repo API and gitweb caching Johannes Schindelin
2008-07-11  9:33 ` Jakub Narebski
2008-07-11 14:07   ` Lea Wiemann
2008-07-11 16:27     ` Abhijit Menon-Sen
2008-07-12 15:08       ` Jakub Narebski
2008-07-19  5:35 ` Lea Wiemann
2008-08-18 19:34 ` Lea Wiemann
2008-08-18 19:39   ` [PATCH 1/3 v10] gitweb: add test suite with Test::WWW::Mechanize::CGI Lea Wiemann
2008-08-19  1:17     ` Junio C Hamano
2008-08-19 14:37       ` Lea Wiemann
2008-08-18 19:39   ` [PATCH 2/3 v2] add new Perl API: Git::Repo, Git::Commit, Git::Tag, and Git::RepoRoot Lea Wiemann
2008-08-19  1:32     ` Junio C Hamano
2008-08-19 15:06       ` Lea Wiemann
2008-08-19 13:51     ` Lea Wiemann [this message]
2008-08-18 19:39   ` [PATCH 3/3 v2] gitweb: use new Git::Repo API, and add optional caching Lea Wiemann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48AACFC7.6070806@gmail.com \
    --to=lewiemann@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).