-
Notifications
You must be signed in to change notification settings - Fork 8
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: hide stack trace on syntax errors #464
Changes from 2 commits
c384e72
b2f2c14
656798d
30c98c0
39f2a11
10bbe18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import type { ExecaError } from 'execa' | ||
|
||
interface BundleErrorOptions { | ||
format: string | ||
} | ||
|
@@ -30,6 +32,11 @@ class BundleError extends Error { | |
*/ | ||
const wrapBundleError = (input: unknown, options?: BundleErrorOptions) => { | ||
if (input instanceof Error) { | ||
if (input.message.includes("The module's source code could not be parsed")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, if you don't mind. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that works - we want to wrap it in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, sorry. Didn't look at this properly. |
||
// eslint-disable-next-line no-param-reassign | ||
input.message = (input as ExecaError).stderr | ||
} | ||
|
||
return new BundleError(input, options) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,8 @@ test('Uses the vendored eszip module instead of fetching it from deno.land', asy | |
}) | ||
|
||
test('Adds a custom error property to user errors during bundling', async () => { | ||
expect.assertions(2) | ||
process.env.NO_COLOR = 'true' | ||
expect.assertions(3) | ||
|
||
const { basePath, cleanup, distPath } = await useFixture('invalid_functions') | ||
const sourceDirectory = join(basePath, 'functions') | ||
|
@@ -102,6 +103,15 @@ test('Adds a custom error property to user errors during bundling', async () => | |
await bundle([sourceDirectory], distPath, declarations, { basePath }) | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(BundleError) | ||
expect((error as BundleError).message).toMatchInlineSnapshot(` | ||
"error: Uncaught (in promise) Error: The module's source code could not be parsed: Unexpected eof at file:///root/functions/func1.ts:1:27 | ||
|
||
export default async () => | ||
~ | ||
const ret = new Error(getStringFromWasm0(arg0, arg1)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find a good way of removing these last couple lines :/ It's hard to pattern-match on this, because there's ANSI color modifiers in between the characters. |
||
^ | ||
at <anonymous> (file:///Users/skn0tt/dev/netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:417:19)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your local paths will be a problem when matching the snapshot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 656798d |
||
`) | ||
expect((error as BundleError).customErrorInfo).toEqual({ | ||
location: { | ||
format: 'eszip', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we not have a single
if
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 10bbe18