Aria Stewart ([info]aredridel) wrote,
  • Mood: accomplished
  • Music: Mountain Chill Mountain Chill - Ouray Colorado Chillout

How I stopped worrying and learned to love errno.h

I just spent 16 hours debugging a complicated, annoying and frustrating problem involving pages not loading in a database frontend, and being spontaneously logged out of a webmail application.

The culprit was the SQLite library (or its bindings to Ruby) being useless with error messages. An example:

#<SQLite3::CantOpenException: could not open database: unable to open database file>

This is not okay. First off, not saying what file is a little annoying, but thankfully, I can tell which file by context since this program only opens one database. Second, and most grievous, it doesn't say which system call failed (though I guess it's open(2))

and third, it doesn't say what error code. There's a reason errno.h exists, people! perror is your friend. A happy little "It didn't work" exception is no replacement for an exception that could read like this: #<SQLite3::CantOpenException: could not open database important.db: EMFILE: The process already has the maximum number of files open.></p>

I wouldn't be hacking about supposing it's a concurrency and locking issue. I'd be knowing that something's not closing files like it's supposed to, like I now know after stracing the process and seeing the real value of errno(3).

Don't do this, folks! Let exceptions carry the most information possible. If you code in C, use perror(3).

Now I get to see why my web framework isn't closing the database on a reload.

Tags: geek

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    Your reply will be screened

    Your IP address will be recorded 

  • 14 comments

[info]aechei

August 29 2008, 20:01:46 UTC 3 years ago

*blinks*

whoa.

i think you just broke my brain.

[info]aredridel

August 29 2008, 20:02:22 UTC 3 years ago

*laughs* I am SUCH a geek. Like whoa.

I get so grumpy with avoidable bugs in software.

[info]aechei

August 29 2008, 20:08:00 UTC 3 years ago

oh, me too. i just don't understand code.

my job actually involves a lot of programming-esque things, i just don't have to deal with code at all because i'm designing user interfaces. but it's all about making stuff efficient and intuitive.

[info]aredridel

August 29 2008, 20:08:46 UTC 3 years ago

Oh, nice. *grins*

That's my favorite part of my work. This part is the one that makes me grumpy.

[info]aechei

August 29 2008, 20:16:56 UTC 3 years ago

yeah, i bet.

I'm an information architect. you might be the only person on my friendslist who would have any idea what that means.

[info]aredridel

August 29 2008, 20:17:32 UTC 3 years ago

*grins* Information architecture is freakin' awesome.

More people need to learn to do it well. It'd make my life a lot easier.

[info]aechei

August 29 2008, 21:09:20 UTC 3 years ago

i shall try!

i'm hoping to gain a better understanding of programming along the way.

[info]peaceofpie

August 30 2008, 01:59:43 UTC 3 years ago

I know what it means!

I had to Wikipedia it to make sure I was right, but I was still right. :D

[info]peaceofpie

August 30 2008, 02:01:32 UTC 3 years ago

I love that there are people like you, so that people like me don't have to understand what you just posted. :)

*loves you*

[info]peaceofpie

August 30 2008, 02:02:43 UTC 3 years ago

And I promise that if I ever find myself coding in C, I will be sure to use perror(3).

I have no idea what I just promised not to do, but I'm sure it will be quite easy for me to keep this promise nonetheless. ;-)

Anonymous

August 30 2008, 19:31:50 UTC 3 years ago

"The perfect error message"

Back in 2006 I had the same experience, so I wrote this:
http://blog.netherlabs.nl/articles/2006/09/08/the-perfect-error-message

Bert Hubert

[info]mentalguy

August 30 2008, 20:00:24 UTC 3 years ago

Fwiw, strerror(3) is often a better choice when you need to send your error message other places besides stderr.

[info]aredridel

September 1 2008, 12:44:09 UTC 3 years ago

Ah, indeed. Even better point. (though at this point, stderr would have been fiiiine)

[info]serishema

September 3 2008, 12:34:53 UTC 3 years ago

This is all too common in the windows world as well. Windows Developers: always log the results of GetLastError() somewhere in addition to the failure message, and also call FormatMessage() passing the value returned by GetLastError() and trap SEH exceptions properly as well and at least log the details of the exception even if you can't handle it recoverably, this way your users will see something more helpful at diagnosing the problem than the standard windows crashed application behaviour.
Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…