diff --git a/IO.lua b/IO.lua index 8305457..0e20f62 100644 --- a/IO.lua +++ b/IO.lua @@ -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 diff --git a/lib.lua b/lib.lua index 36d80a3..6b99558 100644 --- a/lib.lua +++ b/lib.lua @@ -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