Thread

Posted on Tue Oct 24 04:45:55 2006 by lschult2
Error with Carp when using XML::Simple
Hello,

I am having an error with Carp when I use XML::Simple. I created a perl script that shows the issue. The script is setting a sig die handler using CGI::Carp, and then displaying a nice message on the screen. See the end of this message for the script. Here are some links to the script in action.

First Case Second Case

The only difference is that the first case the die happens before XMLin is called, and the second case the die happens after XMLin is called.

When I run this on my local windows box, both cases work (the die is intercepted and displays the nice message). But when I run it on my unix box "sandbox.wineinsight.com", the second case fails every time (The die is not intercepted and no message is displayed).

Here is a perl script that shows the issue:

#!/usr/bin/perl BEGIN { use CGI::Carp qw(fatalsToBrowser set_message); set_message(\&cgidie); $main::SIG{__DIE__}=\&CGI::Carp::croak; } use CGI; use XML::Simple; sub cgidie { local ($message) = @_; print qq~ <html> <H1 style="color: black">Software error:</H1> <pre style="font: 8pt Courier New; color: red">$message</pre> </body> </html> ~; exit; } my $xml = qq~<attr> </attr> ~; die "here:x" if CGI::param('x'); my $attrref = XMLin($xml); die "here:y" if CGI::param('y');
Direct Responses: 3316 | Write a response
Posted on Tue Oct 24 06:13:03 2006 by grantm in response to 3315
Re: Error with Carp when using XML::Simple
Sorry, the only thing I can suggest is looking in your web server's error log to see what error is being encountered. On my Debian Linux box, I don't get any errors (although I did need to change the 'local' to 'my' before it would run at all).
Direct Responses: 3317 | Write a response
Posted on Tue Oct 24 06:27:35 2006 by lschult2 in response to 3316
Re: Error with Carp when using XML::Simple
The error log says "Premature end of script headers". This basically means no HTML was returned. Looking into how CGI::Carp works, it is not calling the &fatalsToBrowser function. The reason it is not is it thinks it's in an eval. It looks like after calling XMLin, that the special variable $^S is set. Then CGI:Carp doesn't dump the error messages to the screen. Do you have any insight into why $^S is set after calling XMLin?
Direct Responses: 3328 | Write a response
Posted on Tue Oct 24 23:30:58 2006 by grantm in response to 3317
Re: Error with Carp when using XML::Simple
No, sorry. XML::Simple does use eval, but doesn't mess with $^S directly. It's possible that the default parser module on your system does but I can't imagine why it would and I haven't been able to reproduce your problem with any of the parser modules I have installed.
Write a response