fix(ext/node): assert.ok compatibility#32173
Conversation
| // TODO(Tango992): This is a workaround, we should find a better way to get the correct source location. | ||
| if (lineNumber === 1 && startColumn > sourceLine.length) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:26Notice 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.
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
Oooof, that's a pretty hard problem. Can we actually skip it for now and address in a follow up?
bartlomieju
left a comment
There was a problem hiding this comment.
Nice work, I left a question
Allows https://github.com/nodejs/node/blob/v24.12.0/test/parallel/test-assert-first-line.js to pass