Skip to content

Fix %todo with a local JsError module, and the location in its message - #9160

Merged
cknitt merged 2 commits into
masterfrom
todo-stdlib-jserror
Nov 1, 2026
Merged

cknitt merged 2 commits into
masterfrom
todo-stdlib-jserror

Conversation

@cknitt

@cknitt cknitt commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Why

%todo expands to a call of JsError.throwWithMessage, resolved by name in the user's scope. A module named JsError in the user's code replaces the standard library one:

module JsError = {
  let throwWithMessage = (s: string) => s
}
let f = (_: int): int => %todo("later")
// This has type: string
// But it's expected to have type: int

The message the expansion throws had two more problems:

  • it contained the absolute path of the source file, so the generated JS depended on where it was built and shipped the build machine's directory;
  • the numbers after the line were character offsets from the start of the file, not columns.

What changes

  • The expansion calls Stdlib_JsError.throwWithMessage, the compilation unit, as Ast_literal already does for Stdlib_RegExp.
  • The location is computed like __LOC__: the file's base name and 0-based columns, so /home/me/app/src/D.res:2:24-29 - Todo becomes D.res:2:14-19 - Todo.

Tests

tests/tests/src/todo_shadowing_test.res defines a local JsError and checks that a %todo still throws. Its generated JS also pins the new message format. Every %todo reports warning 110, so the tests project now keeps that one warning from being an error (-warn-error A-110); all other warnings stay errors.

First of three PRs for the %todo / %debugger items of #8624. Next: a Pexp_todo parsetree node (stacked on this one).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gJFAva9685fjvkajub

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Fix %todo calling a user-defined JsError module instead of the standard library one.
  • Fix the location in the %todo error message: the file's base name instead of its absolute path, and columns instead of character offsets.

Semantic Diff

2 commits · Full page

Expand %todo to the standard library's JsError, located like __LOC__

1d4c028 · cknitt + Claude · Nov 01, 2026, 08:12 UTC

Why

%todo called JsError.throwWithMessage by name, so a user module named JsError replaced it. Its message also embedded the absolute path of the source file, and character offsets from the start of the file as columns.

JS modified (%todo with a local JsError module)

module JsError = {
  let throwWithMessage = (s: string) => s
}
let f = (_: int): int => %todo("later")

diagnostic · Before

This has type: string
But it's expected to have type: int

js · After

function f(param) {
  return Stdlib_JsError.throwWithMessage("A.res:4:25-30 - Todo: later");
}

JS modified (%todo message)

let a = 1
let f = () => %todo

js

-return Stdlib_JsError.throwWithMessage("/home/me/app/src/D.res:2:24-29 - Todo");
+return Stdlib_JsError.throwWithMessage("D.res:2:14-19 - Todo");
✨ Allow the %todo warning in the tests project instead of in the test

0c2890f · cknitt + Claude · Nov 01, 2026, 16:10 UTC · new

Every %todo reports warning 110, which the tests project turned into an error. Answers the Codex review on #9160: rather than disabling the warning in todo_shadowing_test.res, the project keeps 110 a warning (-warn-error A-110), and every other warning stays an error.

@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.67%. Comparing base (f88294f) to head (0c2890f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9160   +/-   ##
=======================================
  Coverage   81.67%   81.67%           
=======================================
  Files         455      455           
  Lines       64859    64859           
=======================================
  Hits        52974    52974           
  Misses      11885    11885           
Files with missing lines Coverage Δ
compiler/frontend/ast_exp_extension.ml 93.75% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9160

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9160

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9160

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9160

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9160

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9160

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9160

commit: 0c2890f

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

@cknitt
cknitt force-pushed the todo-stdlib-jserror branch from 2640a01 to afe9483 Compare November 1, 2026 11:23
Why:
    %todo called `JsError.throwWithMessage` by name, so a user module named
    JsError replaced it. Its message also embedded the absolute path of the
    source file, and character offsets from the start of the file as columns.

JS modified (%todo with a local JsError module):
Example:
    module JsError = {
      let throwWithMessage = (s: string) => s
    }
    let f = (_: int): int => %todo("later")
Before (diagnostic):
    This has type: string
    But it's expected to have type: int
After (js):
    function f(param) {
      return Stdlib_JsError.throwWithMessage("A.res:4:25-30 - Todo: later");
    }

JS modified (%todo message):
Example:
    let a = 1
    let f = () => %todo
Before (js): return Stdlib_JsError.throwWithMessage("/home/me/app/src/D.res:2:24-29 - Todo");
After (js): return Stdlib_JsError.throwWithMessage("D.res:2:14-19 - Todo");

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJFAva9685fjvkajub
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the todo-stdlib-jserror branch from afe9483 to 1d4c028 Compare November 1, 2026 14:08
@cknitt

cknitt commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T16:12:41.199644Z 0c2890f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d4c028142

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/tests/src/todo_shadowing_test.res Resolved
Every %todo reports warning 110, which the tests project turned into an
error. Answers the Codex review on #9160: rather than disabling the warning
in todo_shadowing_test.res, the project keeps 110 a warning (-warn-error
A-110), and every other warning stays an error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gJFAva9685fjvkajub
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt

cknitt commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 0c2890fb3e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt merged commit fbc7de4 into master Nov 1, 2026
26 checks passed
@cknitt
cknitt deleted the todo-stdlib-jserror branch November 1, 2026 19:42
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.

2 participants