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

Forward the correct error if there is an esm syntax error #155

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ async function start () {
// When bundled with pkg, an undefined error is thrown when called with realImport
// When bundled with pkg and using node v20, an ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING error is thrown when called with realImport
// More info at: https://github.com/pinojs/thread-stream/issues/143
worker = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', '')))
try {
worker = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', '')))
} catch {
throw error
}
} else {
throw error
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
},
"standard": {
"ignore": [
"test/ts/**/*"
"test/ts/**/*",
"test/syntax-error.mjs"
]
},
"repository": {
Expand Down
12 changes: 12 additions & 0 deletions test/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,15 @@ test('destroy does not error', function (t) {
t.doesNotThrow(() => stream.end())
})
})

test('syntax error', function (t) {
t.plan(1)

const stream = new ThreadStream({
filename: join(__dirname, 'syntax-error.mjs')
})

stream.on('error', (err) => {
t.equal(err.message, 'Unexpected end of input')
})
})
2 changes: 2 additions & 0 deletions test/syntax-error.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// this is a syntax error
import
Loading