Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Include source url for parsing failures #109

Merged
merged 3 commits into from
Jun 29, 2024

Conversation

timfish
Copy link
Contributor

@timfish timfish commented Jun 18, 2024

Since #106 might not get merged, I cherry picked the improvements to logged error messages when module wrapping fails due to parsing failures.

processModule may parse multiple files in the process of wrapping a module so it's important to log the exact file the fails parsing.

Error: 'import-in-the-middle' failed to wrap 'file:///Users/tim/Documents/Repositories/import-in-the-middle/test/fixtures/json-attributes.mjs'
    at load (/Users/tim/Documents/Repositories/import-in-the-middle/hook.js:306:21)
    at async nextLoad (node:internal/modules/esm/hooks:750:22)
    at async Hooks.load (node:internal/modules/esm/hooks:383:20)
    at async MessagePort.handleMessage (node:internal/modules/esm/worker:199:18) {
  cause: Error: Failed to parse 'file:///Users/tim/Documents/Repositories/import-in-the-middle/test/fixtures/json-attributes.mjs'
      at getExports (/Users/tim/Documents/Repositories/import-in-the-middle/lib/get-exports.js:115:17)
      at async processModule (/Users/tim/Documents/Repositories/import-in-the-middle/hook.js:131:23)
      at async load (/Users/tim/Documents/Repositories/import-in-the-middle/hook.js:269:25)
      at async nextLoad (node:internal/modules/esm/hooks:750:22)
      at async Hooks.load (node:internal/modules/esm/hooks:383:20)
      at async MessagePort.handleMessage (node:internal/modules/esm/worker:199:18) {
    cause: SyntaxError: Unexpected token (1:40)
        at pp$4.raise (/Users/tim/Documents/Repositories/import-in-the-middle/node_modules/acorn/dist/acorn.js:3573:15)
        at pp$9.unexpected (/Users/tim/Documents/Repositories/import-in-the-middle/node_modules/acorn/dist/acorn.js:772:10)
        at pp$9.semicolon (/Users/tim/Documents/Repositories/import-in-the-middle/node_modules/acorn/dist/acorn.js:749:68)
        at Parser.parseImport (/Users/tim/Documents/Repositories/import-in-the-middle/node_modules/acorn-import-attributes/lib/index.js:242:12)
        at pp$8.parseStatement (/Users/tim/Documents/Repositories/import-in-the-middle/node_modules/acorn/dist/acorn.js:948:51)
        at pp$8.parseTopLevel (/Users/tim/Documents/Repositories/import-in-the-middle/node_modules/acorn/dist/acorn.js:829:23)
        at Parser.parse (/Users/tim/Documents/Repositories/import-in-the-middle/node_modules/acorn/dist/acorn.js:601:17)
        at Function.parse (/Users/tim/Documents/Repositories/import-in-the-middle/node_modules/acorn/dist/acorn.js:651:37)
        at getEsmExports (/Users/tim/Documents/Repositories/import-in-the-middle/lib/get-esm-exports.js:37:23)
        at getExports (/Users/tim/Documents/Repositories/import-in-the-middle/lib/get-exports.js:97:14) {
      pos: 40,
      loc: [Position],
      raisedAt: 44
    }
  }
}

@timfish timfish changed the title Fix/improve error fix: Include source url for parsing failures Jun 18, 2024
AbhiPrasad

This comment was marked as outdated.

@timfish

This comment has been minimized.

@jsumners-nr
Copy link
Contributor

Do not use NODE_ENV. I provided feedback in #112 that we should use Node.js's native feature for issuing warnings.

@timfish timfish merged commit 49d69ba into nodejs:main Jun 29, 2024
48 checks passed
@timfish timfish deleted the fix/improve-error branch June 29, 2024 11:51
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