Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I posted a SOPW an hour or so ago on the same script, different problem.

This snippet errors out but it doesn't tell me an error.

############################################ # At this time we are LOGGED IN, so off to the TRADING POST ############################################ print "1"; $mech->get($url2); print "1a"; $mech->submit_form( form_name => "trade1", fields => { "criteria" => 'Lot Number', search_string => "$lotnum" } ) or die "Error: $!"; print "2";
It results in
11a Software error: at /usr/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm line 1492.
Those are test prints so I can see where it stops. Do I have a syntax error? If it helps, I used a fake form name to get it to error out intentionally but it doesn't! So it's something else.

Mechanize is initialized long before this snippet and works for everything else but this.

Replies are listed 'Best First'.
Re: WWW::Mechanize erroring out without producing an error line
by kyle (Abbot) on Jun 30, 2007 at 04:32 UTC

    According to the WWW::Mechanize documentation, submit_form returns a HTTP::Response object, so you should be looking at that for errors. Even if it does return false for some errors, I'm pretty sure it can't set $! to something useful for your error message (according to perlvar, it can only be set to system error messages, see also "How do I return false and set an error in special variable $!"). That said, my quick look at the mech code leads me to think that it throws exceptions with die rather than return errors.

    You might want to look at what's going on at line 1492 of your /usr/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm. My guess is that since you gave it a bogus form name, it's tossing you a die. You can catch that with eval.