Skip to content

An unhandled promise rejection always happens regardless if it's caught down the line #39

@ProjectAuroraRBLX

Description

@ProjectAuroraRBLX

ISSUE
When attaching a catch after a promise is added to the janitor through Janitor:AddPromise(), it will still throw an unhandled rejection:

local Packages = game.ReplicatedStorage.src.Packages

local Janitor = require(Packages.Janitor)
local Promise = require(Packages.Promise)

local janitor = Janitor.new()

janitor:AddPromise(Promise.new(function(resolve, reject)
	task.wait(2)

	reject("THIS REJECTED")
end)):catch(warn)

FIX
The fix seems to be changing the return in Janitor:AddPromise() to the below:

	-- newPromise:finally(function()
	-- 	if Get(self, uniqueId) == newPromise then
	-- 		Remove(self, uniqueId)
	-- 	end
	-- end)

	-- return newPromise :: never

	return newPromise:finally(function()
		if Get(self, uniqueId) == newPromise then
			Remove(self, uniqueId)
		end
	end)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions