Errors in callbacks don't terminate the loop
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 491
- Forks
- 81
- PR merge metrics
- No merged PRs in 30d
Description
As the corocbk.rethrow test shows, errors that happen directly inside an idle source stop the current loop and are returned by loop:run().
However, when the error occurs somewhere nested inside callbacks, the callback chain is aborted, but the error is swallowed.
In the following minimal example, if the query_info operation fails, the error will be printed as GLib warning, but the loop will not quit immediately.
Only once the timeout hits will the loop stop, but report a "successful" true, nil.
The Guide suggests that these errors should either terminate execution or trigger a pcall, neither of which happens here.
local lgi = require("lgi")
local Gio = lgi.Gio
local GLib = lgi.GLib
local File = Gio.File
local loop = GLib.MainLoop()
local co = coroutine.create(function()
local f = File.new_for_path("./does_not.exist")
local ok, err = pcall(f.query_info_async, f, "standard::type", 0, GLib.PRIORITY_DEFAULT, nil, function(_, token)
local _, err = f:query_info_finish(token)
assert(err == nil)
loop:quit()
end)
print(ok, err)
end)
GLib.idle_add(GLib.PRIORITY_DEFAULT, co)
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, function()
loop:quit()
end)
local ok, err = pcall(loop.run, loop)
print(ok, err)
Result:
true nil
(process:17302): Lgi-WARNING **: 11:46:45.041: Error raised while calling 'lgi.cbk (function: 0x55e197403ea0): Gio': test.lua:11: assertion failed!
true nil
Related: #124.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the corocbk.rethrow test in tests/corocbk.lua and compare its direct idle-source behavior with the nested callback example in the issue. Read the callbacks section in docs/guide.md and trace loop:run through the callback chain. Done means errors from nested callbacks are not swallowed and loop:run reports the failure instead of true, nil.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100