lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2014-09-19 21:39 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:
> How do you deal with the following:
>
> 1: You parse the input that you receive and you know it to be well-formed.
> 2: You call a library function that will look for a resource by that name
> and, if it fails, returns `nil, error`.
> 3: That same call may also generate an error. For example, perhaps the
> object contains a dependent resource that is in an invalid state.
>
> I can guess at what the answer to this question is: "if you return nil,
> error_msg, always return nil, error_msg" So, then the onus is on me to call
> pcall if there is any risk that an error would result.
>
> Is that correct?

The way I read Hisham's post, the module should return
nil, error_msg if your input was according to specs but
the operation could not be performed, but it is allowed to
error() if the fault is yours.