Feature Proposal: Deprecate Error.pm

Motivation

Wrote this FP based on CrawfordCurrie comment:
Aside from anything else, I haven't had a chance to comment properly yet. There has been no discussion about adding Try::Tiny to the dependencies - if we do, we have duplicate exception handling modules.

By it's maintainer, the CPAN:Error isn't recommended many years ago. Cite from the module description:
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 the "SEE ALSO" section below for better recommendations.

Description and Documentation

First deprecation warning is in the version 0.17016 from DEC 18, 2009.

Therefore suggesting replace it with the CPAN:Try::Tiny.

Its reverese dependecies shows 944 modules, (vs 93 Error.pm) so the module itself is heavily used - and probably it is in good condition.

The CPAN:Try::Tiny is one of the modules suggested by the current Errror.pm maintainer.

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.

Examples

Impact

%WHATDOESITAFFECT%
edit

Implementation

-- Contributors:

Discussion

If we choose to adopt perl v5.14.2 as the minimum with FW 3.0 (which ImproveOOModel is targeted to) then because of http://perldoc.perl.org/perl5140delta.html#Exception-Handling we may not need any exception handling modules.

(See also RequirePerl510From2017x03)

Try::Tiny has a feature that if you 'return' from inside a block you just leave the block. You do not 'return' to the calling sub - a trap for the unwary.

Other exception handling modules are sophisticated enough to eliminate that, but have many dependencies.

The downside is that we lose syntactic sugar and just use standard perl i.e. eval { ... } if( $@ ... ) { ... } elseif( $@... ) { ... } else {}

Is that so bad?

So, I agree with removing Error, but not necessarily replacing with Try::Tiny.

-- JulianLevens - 06 Jan 2016 - 11:43

Yes, the plain eval is an solution also, but the "sugar" is nice. Similar discussions: Just note, the CPAN:Try::Tiny will be probably loaded anyway /once in the future - when ( IF ) we will use some more CPAN :)/ - just check the above reverse-deps. The TryCatch is nice, but has very heavy deps (mainly the CPAN:Moose) - and because the Moose is rejected, it isn't viable.

-- JozefMojzis - 06 Jan 2016

I introduced Error.pm to Foswiki many years ago, precisely because the eval syntax is so clumsy. I also wanted a reasonably clean way to handle otherwise and always clauses. I looked at shifting to Try::Tiny after the deprecation notice mentioned above, but didn't bother in the end. The Error.pm syntactic sugar is nasty in places - mainly down to the trailing semicolon problem - but is liveable with, once you are aware of the foibles (which are documented), and the extra features have a definite appeal. The negatives are (to me)
  • Using a return inside a handler leaves you confused
  • missing the trailing semicolon is also confusing

But apart from those traps, I don't have a problem with it. I'm not seeing a big reason to move.....?

-- Main.CrawfordCurrie - 06 Jan 2016 - 16:37

There are two reasons for using either Try::Tiny or Error:
  1. Syntactic sugar
  2. Work around perl bugs ref $@ (when perl < v5.14)

I'm not fighting to lose syntactic sugar, but I did think it was worth raising the point for discussion.

On the basis that we use some module or other for syntactic sugar and that module 'fixes' the bugs then then second reason becomes moot.

However, "Error does not localize $@" and from the docs of Error.

*WARNING*

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 the "SEE ALSO" section below for better recommendations.

Basically Try::Tiny does at least remove traps, alas not all (';' and return issues still apply), the modules that do eliminate all traps have a lot of dependencies.

That for me is a good case to move.

-- JulianLevens - 07 Jan 2016 - 10:34

JulianLevens , yes, your warning block is BIGGER than the mine in the Motivation section. wink smile smile

-- JozefMojzis - 07 Jan 2016

Abandoned

-- MichaelDaum - 14 Oct 2024
 
Topic revision: r7 - 14 Oct 2024, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy