Skip to content

feat: improve compile error reporting #220

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

Merged
merged 6 commits into from
Dec 4, 2021
Merged

Conversation

dominikg
Copy link
Member

@dominikg dominikg commented Dec 3, 2021

convert compiler error to a RollupError that is displayed to the user in a more friendly way than the current stack pointing into vite-plugin-svelte.

This is a bit verbose and causes messages to be sent multiple times on console for sveltekit (ssr and regular compile) but at least it's showing the correct file and frame.

fixes #218

@dominikg
Copy link
Member Author

dominikg commented Dec 3, 2021

@benmccann please try it and let me know if that's good enough. We may be able to improve this further by additional handling in kit itself.

@benmccann
Copy link
Member

I think this line needs to be updated as well:

const compiled = compile(finalCode, finalCompileOptions) as Compiled;

Besides that, lgtm.

We may be able to improve this further by additional handling in kit itself.

I'm curious what we might do on the kit side?

@dominikg
Copy link
Member Author

dominikg commented Dec 3, 2021

compile errors are handled for esbuild now too (differently than for vite because it has a different reporting format).

Should we add similar try/catch to svelte.preprocess ? the way i added try/catch both preprocess and compile errors are already caught 😵‍💫

@dominikg dominikg requested a review from bluwy December 3, 2021 15:39
@dominikg
Copy link
Member Author

dominikg commented Dec 4, 2021

i'm having a hard time provoking an error that triggers the esbuild error handling changed in this PR.

@dominikg
Copy link
Member Author

dominikg commented Dec 4, 2021

finally was able to trigger it thanks to @bluwy .

this is how esbuild prebundling errors will be displayed (cli only)

> e2e-tests-configfile-esm@1.0.0 dev /home/dominikg/develop/sveltejs/vite-plugin-svelte/packages/e2e-tests/configfile-esm
> vite

 > ../_test_dependencies/svelte-src-export/src/components/Dependency.svelte:3:5: error: [plugin: vite-plugin-svelte:optimize-svelte] /home/dominikg/develop/sveltejs/vite-plugin-svelte/packages/e2e-tests/_test_dependencies/svelte-src-export/src/components/Dependency.svelte:3:5 Unexpected token
     3 │  foo(;
       ╵      ^
   html:/home/dominikg/develop/sveltejs/vite-plugin-svelte/packages/e2e-tests/configfile-esm/src/App.svelte:23:23: note: The plugin "vite-plugin-svelte:optimize-svelte" was triggered by this import
    23 │ import Dependency from 'e2e-test-dep-svelte-src-export/src/components/Dependency.svelte';~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The link to the file with the error is clickable in intellij idea (and i hope in vscode too)

These esbuild errors should be rare though as the .svelte files are published in a library and hopefully the library maintainers are thoughtful enough to not publish erroneous .svelte files.
Theoretically preprocessor or compiler errors/breaking changes could trigger this for valid .svelte files, but in that case i'd expect a lot more errors everywhere in the project.

vite devserver cli shows this

3:37:14 PM [vite] Internal server error: /home/dominikg/develop/sveltejs/vite-plugin-svelte/packages/playground/kit-demo-app/src/lib/Counter/index.svelte:14:5 Unexpected token
  Plugin: vite-plugin-svelte
  File: /home/dominikg/develop/sveltejs/vite-plugin-svelte/packages/playground/kit-demo-app/src/lib/Counter/index.svelte
   12 |      return ((n % m) + m) % m;
   13 |    }
   14 |    foo(;
               ^
   15 |  </script>
   16 |  

and the overlay looks like this
Screenshot_2021-12-04_15-39-14

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Some format nitpicks

Co-authored-by: Bjorn Lu <34116392+bluwy@users.noreply.github.com>
@dominikg dominikg merged commit df7c570 into main Dec 4, 2021
@dominikg dominikg deleted the feat/report-compiler-errors branch December 4, 2021 15:46
@github-actions github-actions bot mentioned this pull request Dec 4, 2021
@github-actions github-actions bot mentioned this pull request Jul 13, 2022
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.

Better error handling
3 participants