lua-users home
lua-l archive

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


This is related to Dirk's post:

I had a bug that was hard to track down. It was caused by my test script's use of assert for a function that returns `false, error_message` as a return signature, where `error_message` is a table with key/value properties:

```
local s = function(babies)
if babies > 10 then
return false, {416, "Too many babies."}
end

---do lots of stuff, some of which could
-- call `error`

return {200, babies}
end
local p = function(msg)
---process message....
local success, ret, err = pcall(s, msg)
if not success or not ret then
return nil, success and err or ret
else
return ret
end
end


local success, p_res = assert(p(11))
--> C:\lua.exe: (no error message)
```

I don't know if this has broad potential for others, or not, but an error would be welcomed here, as well. This time for having any value that is not a string or `nil` in assert's second argument would have saved me hours of head scratching. Not having a line number/file name was very...difficult.



--Andrew