[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Error handling (was Re: [ANN] Lua 5.3.0 (final) now available)
- From: Sean Conner <sean@...>
- Date: Fri, 16 Jan 2015 16:15:53 -0500
It was thus said that the Great Andrew Starks once stated:
>
> If you always error, you can
> pretend that errors never happen, until you can't. In a garbage
> collected language, the places where you need to clean the state up
> are pretty limited, so this may be more true of Lua than of C, or
> whathaveyou.
But you can still leak resources if you don't clear your references. I
just found such a bug at work at one place, and now I'm afraid of all the
paths I neglected to clean up references leading up to that point.
And the path is checking a SIP message for validity, so it's a lot of
if not this_header then
reply "you bozo!"
end
if this_header ~= "that" then
reply "you bozo!"
end
And I can't just toss an error here because there are two (or three, if
you squint) distinct phases to the processing:
We've received the initial message, check for validity and send back
ACK or NAK.
Send a new message to something else (it may be the oritinal sender;
it may not be), and wait for an ACK or NACK.
which is running as a coroutine, which has its own peculiarities.
Handling errors in the first half is different from the second half (the
third phase is just skipping the second phase if we receive a particual
message).
> `return nil, error_msg` forces you to write more code every time you
> call that function.
But that's pretty much what I"m doing now.
-spc (Off to check all the code paths now ... sigh)