local function d(d,...)return d,select("\035",...),{...}end local function y(d)assert(d~=nil)return function(y)if type(y)=="\116\097\098\108\101"then return y end return Error.new({error=y,kind=Error.Kind.ExecutionError,trace=debug.traceback(tostring(y),2),context="\080\114\111\109\105\115\101 \099\114\101\097\116\101\100 \097\116\058\n\n"..d})end end
--[[
	Returns first value (success), and packs all following values.
]]
local function packResult(success, ...)
	return success, select("#", ...), { ... }
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(tostring(err), 2),
			context = "Promise created at:\n\n" .. traceback,
		})
	end
end
