Skip to content

fix(ext/node): assert.ok compatibility#32173

Merged
Tango992 merged 7 commits intodenoland:mainfrom
Tango992:fix-node-assert-ok
Feb 16, 2026
Merged

fix(ext/node): assert.ok compatibility#32173
Tango992 merged 7 commits intodenoland:mainfrom
Tango992:fix-node-assert-ok

Conversation

@Tango992
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work here

Comment on lines +93 to +94
// TODO(Tango992): This is a workaround, we should find a better way to get the correct source location.
if (lineNumber === 1 && startColumn > sourceLine.length) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you ber more specific here? What would you want to do better? Maybe we need to add some sort of helper to 01_require.js?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah so for CJS modules, we wrapped the code with this before executing it. This causes the first line of the code to have an offset.

Let's say we have a code named index.cjs

throw new Error("foo")

Running node index.cjs outputs:

/some-path/index.cjs:1
throw new Error("Foo")
^

Error: Foo
    at Object.<anonymous> (/some-path/index.cjs:1:7)
    at Module._compile (node:internal/modules/cjs/loader:1811:14)
    at Object..js (node:internal/modules/cjs/loader:1942:10)
    at Module.load (node:internal/modules/cjs/loader:1532:32)
    at Module._load (node:internal/modules/cjs/loader:1334:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
    at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
    at node:internal/main/run_main_module:33:47

Node.js v25.6.1

On the other hand, running deno index.cjs outputs:

deno index.cjs 
error: Uncaught (in promise) Error: Foo
Warning Couldn't format source line: Column 228 is out of bounds (source may have changed at runtime)
    at file:///some-path/index.cjs:1:228
    at Object.<anonymous> (file:///some-path/index.cjs:3:3)
    at Module._compile (node:module:759:34)
    at Object.loadCjs [as .cjs] (node:module:789:10)
    at Module.load (node:module:677:32)
    at Module._load (node:module:535:12)
    at file:///some-path/index.cjs:5:26

Notice that the stack traces point to non existing locations: file:///some-path/index.cjs:1:228, file:///some-path/index.cjs:3:3, and file:///some-path/index.cjs:5:26. This unables us to extract the correct first expression for this test. Hence why the if statement is needed.

Copy link
Copy Markdown
Contributor Author

@Tango992 Tango992 Feb 15, 2026

Choose a reason for hiding this comment

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

Maybe we need to add some sort of helper to 01_require.js?

I did try to create a helper function to address this, but none worked (or maybe I stepped in the wrong direction). I think we need more appropriate solution instead of patching the stack traces 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should be related: #32096

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oooof, that's a pretty hard problem. Can we actually skip it for now and address in a follow up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure

Copy link
Copy Markdown
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Nice work, I left a question

@Tango992 Tango992 merged commit 02c6d3d into denoland:main Feb 16, 2026
86 checks passed
@Tango992 Tango992 deleted the fix-node-assert-ok branch February 16, 2026 14: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.

2 participants