Skip to content

fix(concurrency): report a root coroutine error once, not twice - #22

Merged
zombocoder merged 2 commits into
zombocoder:mainfrom
Craftegy-NextGen:fix/root-coroutine-duplicate-error
Oct 27, 2026
Merged

zombocoder merged 2 commits into
zombocoder:mainfrom
Craftegy-NextGen:fix/root-coroutine-duplicate-error

Conversation

@sashml

@sashml sashml commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When Main.main() fails at runtime, the error is printed twice:

Error in coroutine #0: Unresolved Reference Error: Variable 'undefinedVariable' not found
Error: Unresolved Reference Error: Variable 'undefinedVariable' not found

The scheduler prints every failed coroutine, including the root one. But the root coroutine's
exception is also captured in root_exception_, re-thrown by Interpreter::execute() and reported by
main.cpp.

Fix

In Scheduler::run(), print only errors from non-root coroutines. The root coroutine's exception is
still captured and re-thrown by its only caller, so the program still exits 1 with a single
Error: ... line. Errors in spawned coroutines are reported exactly as before.

Tests

Two cases added to tests/test_root_exception.cpp:

  • root_exception_not_printed_by_scheduler: the root error is captured and not printed by the
    scheduler. It fails without the fix (stderr contains Error in coroutine #0).
  • non_root_exception_still_printed: a spawned coroutine's error is still printed.

Verification

  • Windows 10, MSVC 2022, Release, Ninja, GoogleTest from vcpkg, on current main with this branch merged: build OK, o2l_tests 528/528 passing.
  • A failing main() prints one Error: ... line and exits 1; a clean one exits 0. The same program on current main prints both lines shown above.
  • clang-format (repository .clang-format) reports nothing on the changed lines.
  • Linux and macOS: covered by CI.

svaiml and others added 2 commits October 25, 2026 02:52
When Main.main() fails, the scheduler printed "Error in coroutine #0: ..."
and Interpreter::execute() then re-threw the captured root exception,
which main.cpp reports again as "Error: ...". Every runtime error in a
program's main method therefore appeared twice on stderr.

The root coroutine's exception is already captured in root_exception_ and
re-thrown by its only caller, so only print errors from non-root
coroutines in the scheduler. Behavior and exit codes are otherwise
unchanged.

Signed-off-by: svaiml <88979468+svaiml@users.noreply.github.com>
…ll printed

root_exception_not_printed_by_scheduler: a failing root coroutine is
captured in root_exception_ and not also printed by the scheduler (fails
without the previous commit: stderr contains "Error in coroutine #0").

non_root_exception_still_printed: errors from non-root coroutines are
still reported by the scheduler.

Signed-off-by: sashml <sashml@users.noreply.github.com>
@zombocoder
zombocoder merged commit 9bf0f08 into zombocoder:main Oct 27, 2026
6 checks passed
@sashml
sashml deleted the fix/root-coroutine-duplicate-error branch October 27, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants