[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua interface standards
- From: Sean Conner <sean@...>
- Date: Sun, 23 Apr 2017 03:54:37 -0400
It was thus said that the Great Martin once stated:
> Also there will be need to standartize behavior for bad data both
> when decoding and coding. For example you can't serialize table
> with table-type keys to JSON. Or table with cycles. Should error()
> be raised or just (nil, err_msg) returned?
I actually prefer (nil, err_value). First, the caller might be able to
deal with the error (don't force me to pcall() just to capture an error I
can handle), and an error value is easier to check than a string (especially
given locales). It's not uncommon for my code to do:
local remote,data,err = socket:recv()
if not remote then
if err == errno.ETIMEDOUT then
-- timed out, probably return or something
if err ~= errno.EINTR then
syslog('error',"socket:recv() = %s",errno[err])
-- happy path
> Should standard provide .verify(t) function?
What should this do?
> What if I want to serialize parts that can be serialized and omit
> others? Should standard provide .align(t) function?
Least-common-demoninitor behavior is to assume error() and if it can't
serialize what you give it, then error().