Ignore some normal errors in IO

This commit is contained in:
osmarks 2018-08-15 19:10:52 +01:00
parent be5429d6b4
commit d0d2815730
2 changed files with 10 additions and 2 deletions

2
IO.lua
View File

@ -33,7 +33,7 @@ local function main()
local request = w.string_to_item(item_name)
request.type = "extract"
request.destination_inventory = conf.chest
local result = w.unwrap(w.query_by_type("storage", request), "extracting items")
local result = w.unwrap(w.query_by_type("storage", request), "extracting items", { w.errors.NOITEMS })
print("Moved", result.moved, item_name, "from storage.")
end
end

10
lib.lua
View File

@ -261,10 +261,18 @@ local function init()
end
-- Rust-style unwrap. If x is an OK table, will take out its contents and return them - if error, will crash and print it, with msg if provided
local function unwrap(x, msg)
local function unwrap(x, msg, ignore)
if not x or type(x) ~= "table" or not x.type then x = errors.make(errors.INTERNAL, "Error/response object is invalid. This is probably a problem with the node being contacted.") end
if x.type == "error" then
if ignore then
for _, etype in pairs(ignore) do
if x.error == etype then
return
end
end
end
local text = "An error occured"
if msg then text = text .. " " .. msg
else text = text .. "!" end