mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Allow rejection with error objects
This commit is contained in:
parent
faa4f73dd3
commit
266e265e20
2 changed files with 20 additions and 1 deletions
11
lib/init.lua
11
lib/init.lua
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue