Allow rejection with error objects

This commit is contained in:
Eryn Lynn 2020-05-11 15:43:35 -04:00
parent faa4f73dd3
commit 266e265e20
2 changed files with 20 additions and 1 deletions

View file

@ -131,11 +131,20 @@ end
local function makeErrorHandler(traceback)
assert(traceback ~= nil)
return function(err)
-- If the error object is already a table, forward it directly.
-- Should we extend the error here and add our own trace?
if type(err) == "table" then
return err
end
return Error.new({
error = err,
kind = Error.Kind.ExecutionError,
trace = debug.traceback(err, 2),
trace = debug.traceback(tostring(err), 2),
context = "Promise created at:\n\n" .. traceback
})
end

View file

@ -925,6 +925,16 @@ return function()
expect(errorText:find("errortext")).to.be.ok()
end)
it("should reject with error objects", function()
local object = {}
local success, value = Promise.try(function()
error(object)
end):_unwrap()
expect(success).to.equal(false)
expect(value).to.equal(object)
end)
it("should catch asynchronous errors", function()
local bindable = Instance.new("BindableEvent")
local promise = Promise.try(function()