From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: "Petr Baudis" <pasky@suse.cz>, "Alex Riesen" <raa.lkml@gmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [1.8.0] perl/Git.pm: moving away from using Error.pm module
Date: Sun, 20 Feb 2011 23:46:33 +0100 [thread overview]
Message-ID: <201102202346.36410.jnareb@gmail.com> (raw)
Proposal:
Replace use of Error.pm module in Git.pm with either Exception::Class
based error class, or using 'carp'/'croak' from Carp, or both by adding
an option to set error handler in 'Git' class (like e.g. in 'CHI'
module on CPAN).
While at it, if we are to require some extra non-core module, instead
of using 'private-<module>.pm', use more standard 'inc/' directory
(i.e. 'inc/<module>.pm').
Also get rid of git_cmd_try - encourage to use TryCatch or Try::Tiny
instead, or even 'eval { ... }' as a way to catch thrown exceptions.
Rationale:
An extract from the Error.pm documentation:
Using the "Error" module is *no longer recommended* due to the
black-magical nature of its syntactic sugar, which often tends to
break. Its maintainers have stopped actively writing code that uses
it, and discourage people from doing so.
"SEE ALSO" section therein mentions the following possible replacements:
See Exception::Class for a different module providing Object-Oriented
exception handling, along with a convenient syntax for declaring
hierarchies for them. It doesn't provide Error's syntactic sugar of
`try { ... }, catch { ... }`, etc. which may be a good thing or a bad
thing based on what you want. (Because Error's syntactic sugar tends
to break.)
Error::Exception aims to combine Error and Exception::Class "with
correct stringification".
TryCatch and Try::Tiny are similar in concept to Error.pm only
providing a syntax that hopefully breaks less.
Unfortunately, neither of those modules is in core (well, neither is
Error.pm).
Risks:
Out of git commands and helpers implemented in Perl and using Git.pm
module, only git-svn.perl uses 'try_git_cmd' directly. git-send-email
uses 'eval { ... }' to catch exceptions thrown by ->repository()
constructor; perhaps other scripts do the same. There is some risk of
breaking git with this change...
Third party modules and scripts might have also depend on Git.pm using
Error.pm... though I wonder how many of Perl scripts use Git instead of
for example Git::Wrapper or other git-related Perl module from CPAN.
Migration plan:
I don't really have migration plan yet, because I amnot sure what
solution should be implemented.
1. One possible solution would be to just replace Error with
Exception::Class (or Git::Exception based in this class), and leave
everything else as close to current state as possible. Removing
try_git_cmd would be second step...
2. Another solution would be to use 'on_error' to set error handler,
with support for 'die'/'croak', Error and Exception::Class based
exceptions, with default to 'croak'. In this case we wouldn't need any
extra module, but testing structural exceptions would be harder.
We would have to replace try_git_cmd with eval, or Try::Tiny.
3. Yet another would be to leave Git module as it is now, and create
new modules: Git::Cmd, Git::Repo, Git::Config etc.
--
Jakub Narebski
Poland
next reply other threads:[~2011-02-20 22:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-20 22:46 Jakub Narebski [this message]
2011-02-21 7:20 ` [1.8.0] perl/Git.pm: moving away from using Error.pm module Junio C Hamano
2011-02-21 9:31 ` Jakub Narebski
2011-02-21 11:02 ` Nick
2011-02-21 12:12 ` Jakub Narebski
2011-02-21 12:31 ` Ævar Arnfjörð Bjarmason
2011-04-15 23:35 ` Avner
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=201102202346.36410.jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=pasky@suse.cz \
--cc=raa.lkml@gmail.com \
/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).