git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[1.8.0] perl/Git.pm: moving away from using Error.pm module

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 20, 2011, 22:46 UTC
Message-ID
<201102202346.36410.jnareb@gmail.com>
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: Junio C Hamano
Message 1 of 7 in “[1.8.0] perl/Git.pm: moving away from using Error.pm module”
  1. Jakub NarebskiFeb 20, 2011
  2. Junio C HamanoFeb 21, 2011
  3. Jakub NarebskiFeb 21, 2011
  4. NickFeb 21, 2011
  5. Jakub NarebskiFeb 21, 2011
  6. Ævar Arnfjörð BjarmasonFeb 21, 2011
  7. AvnerApr 15, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.