Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: WWW::Mechanize - error on geting non-existing page

by Your Mother (Canon)
on Nov 06, 2011 at 17:10 UTC ( #936309=note: print w/ replies, xml ) Need Help??


in reply to Re^3: WWW::Mechanize - error on geting non-existing page
in thread WWW::Mechanize - error on geting non-existing page

Öwell, all examples really. Though it depends on how you see it. I never advocated ignoring return states.

Not finding a page online is not an exception(al case). Itís entirely normal. Should your car blow-up if a road-sign is missing or should the driver revisit the map? If you need to deal with any of the various 400s and 500s, itís just easier on the hacker to not wrap it up in evals. The end code will have identical functionality: i.e., every request is checked for success or unexpected codes and then processed accordingly. All the exception handling buys you here is additional complexity (and the chance to fall into eval problems with disappearing $@ if youíre not careful).

The change to make this stuff fatal by default is recent-ish. For most of the life of Mech, it wasnít this way so it was a pretty big style break for those of us using it from the beginning, and I think most LWP hackers are already accustomed to checking $response->is_success habitually.

There may be some value in the fatals for the newcomer who has incorrect expectations but for the experienced user of the kit itís just an annoying hoop (and a bunch of broken scripts when the update came through but I digressÖ uh, and whine).


Comment on Re^4: WWW::Mechanize - error on geting non-existing page
Select or Download Code
Re^5: WWW::Mechanize - error on geting non-existing page
by GrandFather (Cardinal) on Nov 06, 2011 at 20:14 UTC

    I hear where you are coming from, but it sounds a little like "We didn't have warnings in the past, we always checked using defined. Why should we switch to using them now?". To me the difference is between having to check everywhere and maybe getting bitten bad if you missed something, versus getting a noisy failure if something unanticipated happens.

    In most cases I'd rather have a noisy failure and deal with it than a quiet failure that may just plough on and destroy the world.

    True laziness is hard work

      Let me put it differently. Mech is a browser emulator. How sensible would it be for a browser to quit on 404s? Mech is a subclass of LWP::UserAgent. How sensible is it to change default behavior radically? Both are obvious mistakes.

      This particular change was supposed to help new users, one imagines, but Iíve seen this question come up constantly since it was made: What the heck is going on? My script just quits!? And for adept users it broke all existing scripts and forces a new line of code in everything. I love the functionality of being able to put in your own code ref in but having it be the default is a mistake: conceptually, historically, and expectation-wise.

        Ah, yes I agree that changing default behaviour in that way is just a bad nasty horrible idea!

        True laziness is hard work
        1.49_01     Sat Sep 27 23:50:04 CDT 2008
        ========================================
        [THINGS THAT MAY BREAK YOUR CODE]
        The autocheck argument to the constructor is now ON by default,
        unless WWW::Mechanize is being subclassed.  There are so many new
        programmers whose ->get() calls fail unchecked that I'm now putting
        on the seat belts for them.
        
        On moving forward and breaking compatibility is a gentle rant about precisely this. We had about 2 years of "crap, my recovery script I run once every forever is dying and $APPLICATION is dead in the water! HALP!" emails at $PREVIOUS_WORKPLACE because of this change. The old behavior would allow these scripts to work because autocheck was off, and the scripts were checking the errors; once it was on automatically, the scripts would crap out despite the "proper" error handling being in place.

        The middle of an emergency is not when you want to try to explain how this change that has broken things and is costing money was, really, a good idea, and how, yes, they will have to patch the script if they want to move forward, and yes, they will have to do this on the production machine, and yes, they will have to get all the relevant people out of bed, and no, I don't think that's where the author's head was.

        As I mention in the above node, this could have been done better, with examples of how so.

Re^5: WWW::Mechanize - error on geting non-existing page
by Limbic~Region (Chancellor) on Nov 09, 2011 at 17:06 UTC
    Your Mother,
    If instead of:

    You can also just set onerror => undef which is easier and less error prone than eval/try style code.

    You had said:

    This behavior can be turned off by either setting onerror to undef or by turning autocheck off in the constructor. The purpose behind this was the author's attempt to protect new users from themselves. Just as you shouldn't assume that your call to open was successful, you shouldn't assume your call to get was either. It will be your responsibility to check each success for is_success/status and handle any recoverable situations yourself if you do this.

    I would never have commented. Personally, I like having the code blow up to remind me of places I haven't properly checked the status and leave it on by default but I can see your point as well.

    Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://936309]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-12-27 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls