Ahh the great JDJ awards :) Sun DB: Known for software success, watch out Oracle, Sun DB is coming
Feb 05

Why you should check for errors :)

Tech Add comments

What’s wrong with this picture:

open(OUTFILE,">${tmpdir}${code}");
print OUTFILE $scode;
close(OUTFILE);

Well, it may not be my style. But, the biggest problem is What happens if the OUTFILE isn’t created?

I ran into this when my security codes weren’t working. There was no bad output, other than a glimpsing error that I saw on a screen saying that there was something up with the print OUTFILE $scode line.

The problem was that the $tmpdir had gotten bad permissions.

It would be a lot nicer if we had:

open OUTFILE, “>${tmpdir}${code}” or die “I guess I should tell someone that this didn’t work. opening ${….}: $!”;

I always like to run my scripts with -w, use strict; etc… like a good boy. This had me change mt-scode.cgi too:

#my $cookie = $cgi->cookie(-name=>’code’,-value=>$code);

$cookie doesn’t seem to be used anymore and -name=>code was bare instead of quoted anyway.

Now everyone is happy, and the codes are back :)

4 Responses to “Why you should check for errors :)”

  1. Cedric Says:

    I’ve seen that happen as well with MT. At some point, my weblog stopped working completely and it took me a while to realize that mt.cgi had been chmod’ed 000 owned by root.

    I think the MT code has quite a few bugs and can leave things in an inconsistent state if things go wrong.

  2. Cedric Says:

    I’ve seen that happen as well with MT. At some point, my weblog stopped working completely and it took me a while to realize that mt.cgi had been chmod’ed 000 owned by root.

    I think the MT code has quite a few bugs and can leave things in an inconsistent state if things go wrong.

  3. Mike Spille Says:

    Posting perl code Dion, for shame :-)

    I think this is a good example on why exceptions are good. It also shows the difficulty with supporting a notion like ‘bare words’ in a language. Groovy should take note of this with their builder idea, and hopefully they’ll have a ’strict’ mode as well.

  4. Mike Spille Says:

    Posting perl code Dion, for shame :-)

    I think this is a good example on why exceptions are good. It also shows the difficulty with supporting a notion like ‘bare words’ in a language. Groovy should take note of this with their builder idea, and hopefully they’ll have a ’strict’ mode as well.

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What is the number before 3? (just put in the digit)