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

I tracked a bug in my script down to one small section of code but I can't get a legit error response. Can someone help me get it to spit out an error that'd be useful for fixing whatever problem there is?
CODE $mech->submit_form( form_number => $number, fields => \%fields, ) or die "Error"; }
ERROR Software error: at /usr/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm line 1492.
I'd imagine it'd at least print ERROR, but it does not, so for the life of me I can't figure out what's wrong.

Replies are listed 'Best First'.
Re: how to get useful errors with WWW::Mechanize
by MonkE (Hermit) on Oct 16, 2006 at 18:42 UTC
    After looking at the (5.8.8) source code, I'd have to say that in your case I would first insure that I was using a valid form number. Then I would check your "fields" hash to make sure it is good. It looks like it expects a hash. Your best bet would be to look at line 1492 of /usr/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm on your computer.

    From Mechanize.pm (5.8.8): Notice the "or die" code.

    sub submit_form { my( $self, %args ) = @_ ; for ( keys %args ) { if ( !/^(form_(number|name)|fields|button|x|y)$/ ) { $self->warn( qq{Unknown submit_form parameter "$_"} ); } } if ( my $form_number = $args{'form_number'} ) { $self->form_number( $form_number ) or die; } elsif ( my $form_name = $args{'form_name'} ) { $self->form_name( $form_name ) or die; } if ( my $fields = $args{'fields'} ) { if ( isa( $fields, 'HASH' ) ) { $self->set_fields( %{$fields} ) ; } # TODO: What if it's not a hash? We just ignore it silently +? } my $response; if ( $args{button} ) { $response = $self->click( $args{button}, $args{x} || 0, $args{ +y} || 0 ); }
Re: how to get useful errors with WWW::Mechanize
by ptum (Priest) on Oct 16, 2006 at 18:08 UTC

    Did you intentionally omit the (optional) 'button' argument to submit_form? Why the comma character after \%fields? It seems to me that the interpreter is complaining about your failure to call submit_form in a recognizable way.

    Update: Yeah, sorry, that was nonsense -- a quick sample script works fine with or without the comma after \%fields. (Blush).

    Have you tried using Data::Dumper to look at the contents of $mech before you attempt the submit_form? I'm getting decent error messages in my sample attempt with screwed up arguments (no form by that number exists, no field by that name exists, etc.). What version of WWW::Mechanize are you using? Line 1492 on the most recent version is in the middle of some POD ...

      Yes, it was intentionally omitted because it's optional. As for the trailing comma, that was a mistake but it was removed and the unknown error still errors out.

      Thank you

        I also added button=>"post" as suggested and it still errors out.

        Anyone have other ideas?