Skip to content

Commit 346d2e4

Browse files
committed
Change NoYield to use optional coroutine argument for debug.traceback.
This is part of stock Lua, but was only turned on it Roblox fairly recently. This should stop Rodux from munching your stacks when a function mistakenly yields.
1 parent b8ba486 commit 346d2e4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/NoYield.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ local function resultHandler(co, ok, ...)
1414
end
1515

1616
if coroutine.status(co) ~= "dead" then
17-
error("Attempted to yield inside Changed event!", 2)
17+
error(debug.traceback(co, "Attempted to yield inside Changed event!"), 2)
1818
end
1919

2020
return ...

lib/NoYield.spec.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ return function()
2323
local preCount = 0
2424
local postCount = 0
2525

26-
local function test()
26+
local function testMethod()
2727
preCount = preCount + 1
2828
wait()
2929
postCount = postCount + 1
3030
end
3131

32-
expect(function()
33-
NoYield(test)
34-
end).to.throw()
32+
local ok, err = pcall(NoYield, testMethod)
3533

3634
expect(preCount).to.equal(1)
3735
expect(postCount).to.equal(0)
36+
37+
expect(ok).to.equal(false)
38+
expect(err:find("wait")).to.be.ok()
39+
expect(err:find("NoYield.spec")).to.be.ok()
3840
end)
3941

4042
it("should propagate error messages", function()

0 commit comments

Comments
 (0)