Skip to content

Make the todo example return a failing status when loading fails - #34

Open
Faizaanp wants to merge 1 commit into
puddi-lang:mainfrom
Faizaanp:fix/issue-20-todo-exit-status
Open

Faizaanp wants to merge 1 commit into
puddi-lang:mainfrom
Faizaanp:fix/issue-20-todo-exit-status

Conversation

@Faizaanp

@Faizaanp Faizaanp commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

The bundled todo example reported a missing or invalid todos.json but still exited with status 0, so scripts could not distinguish a load failure from a successful run. It now returns a Result from main, letting Puddi print "error: ..." and exit with a failing status. The successful example output is unchanged.

What changed

  • examples/todo/src/main.pud - main now returns Result<(), AppErr> and uses ? on load("todos.json") instead of printing "could not load: ..." and returning unit.
  • tests/run.rs - added todo_example_reports_load_failure, which runs the example from a temporary copy without todos.json (asserting non-zero exit plus an error message) and asserts the bundled example still exits 0 with unchanged output.
  • CHANGELOG.md - added a Fixed entry under Unreleased referencing Make the todo example return a failing status when loading fails #20.

How verified

  • Reproduced the bug on unmodified code with the prebuilt binary (PUD_HOST=node): with no todos.json, pud run printed "could not load: io: not found: ..." and exited 0. The bundled example printed "2 of 4 left", " - add async", " - publish packages" and exited 0.
  • After the fix, the same repro with the worktree-built binary (embedded runtime) prints "error: io: not found: NoEntry" and exits 1; the bundled example still prints the same three lines and exits 0.
  • cargo test todo_example_reports_load_failure -- --nocapture -> 1 passed, 0 failed (exit 0).
  • cargo test -- --skip conformance_suite -> all passed (3 unit + 6 integration tests, 0 failed; exit 0), including todo_example_reports_load_failure and run_programs. Debug profile used because a release build was prohibitively slow in this environment.

Regression test

todo_example_reports_load_failure creates a temporary directory, copies pud.toml and src/main.pud from examples/todo (deliberately omitting todos.json), runs pud run from that directory, and asserts a non-zero exit status plus an "error:" / "not found" message. It also asserts the bundled example still exits 0 with output exactly:

2 of 4 left
 - add async
 - publish packages

The temp directory is removed before the assertions.

Successful output unchanged

The three lines above are identical before and after the fix, with exit status 0.

Fixes #20

@ghfind-review ghfind-review Bot added the review: medium ghfind author score; see https://ghfind.com label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: medium ghfind author score; see https://ghfind.com

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the todo example return a failing status when loading fails

1 participant