Skip to content

docs(env): migrate README examples from Result[T, String] to raise - #3813

Merged
bobzhang merged 1 commit into
mainfrom
hongbo/result-to-raise-docs
Aug 18, 2026
Merged

bobzhang merged 1 commit into
mainfrom
hongbo/result-to-raise-docs

Conversation

@bobzhang

Copy link
Copy Markdown
Contributor

Follow-up to the result_error_return diagnostic (warning 78, currently off by default): "Prefer T raise E for failable APIs. Return Result[T, E] only when success/failure must be represented as ordinary data."

Finding

Running moon check --target all --warn-list +result_error_return over core produces zero warnings — library code is already fully raise-based. The only places still teaching the discouraged Result-for-failure style were doc examples in env/README.mbt.md (Result[T, String] with Err("message")).

Change

The three env examples (parse_command, validate_args, validate_and_parse_args) now declare -> T raise Failure, raise the standard Failure error, and demonstrate the canonical expected-failure shape (try ... catch { Failure(msg) => ... } noraise { _ => fail(...) }). The unknown-command assertion got stronger in the process (exact message instead of a length check).

Deliberate keeps (Result-as-ordinary-data carve-out)

  • builtin/README.mbt.md divide — the section documents the Result type itself
  • lazy_list/README.mbt.md maybe_double — failure cached as data inside a lazy structure (the surrounding prose explains why fallible callbacks don't fit lazy maps)
  • strconv/int_test.mbt helpers — bridge the raising parser into Result-typed test tables

Review

Reviewed by Codex CLI (codex-cli 0.144.1): "No findings; approved for merge. Rewrites are behaviorally equivalent and idiomatic... Assertions preserve intent... Agree with all deliberate keeps."

Signed-off-by: Codex CLI codex@openai.com

Validation

  • moon check clean; moon fmt applied
  • moon test: 6715 passed, 0 failed (env package 16/16)

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 15, 2026 14:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the env package documentation examples to align with the library’s preferred failable-API style (T raise E) instead of returning Result[T, String], matching the result_error_return diagnostic guidance.

Changes:

  • Migrated the parse_command, validate_args, and validate_and_parse_args README examples from Result[...] returns to raise Failure.
  • Updated example call sites to use try ... catch ... noraise ... for expected-failure handling.
  • Strengthened the unknown-command example assertion to check the exact error message.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread env/README.mbt.md
Ok(_) => inspect(false, content="true")
Err(msg) => inspect(msg.length() > 10, content="true") // Should have error message
inspect(result, content="Showing help information")
try parse_command(["program", "invalid"]) |> ignore catch {
@coveralls

coveralls commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 6152

Coverage remained the same at 90.876%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 17864
Covered Lines: 16234
Line Coverage: 90.88%
Coverage Strength: 332690.02 hits per line

💛 - Coveralls

The result_error_return diagnostic (warning 78) guides failable APIs
toward `T raise E` over `Result[T, E]`. Core library code is already
clean under this warning on all backends; these README examples were
the remaining places teaching the discouraged Result-for-failure
style. Rewrite them to raise the standard `Failure` error and use the
canonical try/catch/noraise shape for expected failures.

Left as-is deliberately (Result-as-ordinary-data carve-out):
- builtin/README.mbt.md `divide` — documents the Result type itself
- lazy_list/README.mbt.md `maybe_double` — failure stored as data in
  a lazy structure
- strconv/int_test.mbt helpers — feed Result-typed test tables

Reviewed by Codex CLI (codex-cli 0.144.1): "No findings; approved for
merge... Agree with all deliberate keeps."

Signed-off-by: Codex CLI <codex@openai.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bobzhang
bobzhang force-pushed the hongbo/result-to-raise-docs branch from 9992957 to f551576 Compare August 18, 2026 09:34
@bobzhang
bobzhang merged commit 4728bd7 into main Aug 18, 2026
15 checks passed
@bobzhang
bobzhang deleted the hongbo/result-to-raise-docs branch August 18, 2026 09:45
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