Aria Stewart ([info]aredridel) wrote,
@ 2008-08-29 12:26:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Current mood:accomplished
Current music:Mountain Chill Mountain Chill - Ouray Colorado Chillout
Entry tags:geek

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.



(Post a new comment)


[info]aechei
2008-08-29 08:01 pm UTC (link)
*blinks*

whoa.

i think you just broke my brain.

(Reply to this) (Thread)


[info]aredridel
2008-08-29 08:02 pm UTC (link)
*laughs* I am SUCH a geek. Like whoa.

I get so grumpy with avoidable bugs in software.

(Reply to this) (Parent)(Thread)


[info]aechei
2008-08-29 08:08 pm UTC (link)
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.

(Reply to this) (Parent)(Thread)


[info]aredridel
2008-08-29 08:08 pm UTC (link)
Oh, nice. *grins*

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

(Reply to this) (Parent)(Thread)


[info]aechei
2008-08-29 08:16 pm UTC (link)
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.

(Reply to this) (Parent)(Thread)


[info]aredridel
2008-08-29 08:17 pm UTC (link)
*grins* Information architecture is freakin' awesome.

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

(Reply to this) (Parent)(Thread)


[info]aechei
2008-08-29 09:09 pm UTC (link)
i shall try!

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

(Reply to this) (Parent)


[info]peaceofpie
2008-08-30 01:59 am UTC (link)
I know what it means!

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

(Reply to this) (Parent)


[info]peaceofpie
2008-08-30 02:01 am UTC (link)
I love that there are people like you, so that people like me don't have to understand what you just posted. :)

*loves you*

(Reply to this)


[info]peaceofpie
2008-08-30 02:02 am UTC (link)
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. ;-)

(Reply to this)

"The perfect error message"
(Anonymous)
2008-08-30 07:31 pm UTC (link)
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

(Reply to this)


[info]mentalguy
2008-08-30 08:00 pm UTC (link)
Fwiw, strerror(3) is often a better choice when you need to send your error message other places besides stderr.

(Reply to this) (Thread)


[info]aredridel
2008-09-01 12:44 pm UTC (link)
Ah, indeed. Even better point. (though at this point, stderr would have been fiiiine)

(Reply to this) (Parent)


[info]serishema
2008-09-03 12:34 pm UTC (link)
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.

(Reply to this)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…