dominikg / svite

svelte integration for vite
MIT License
373 stars 21 forks source link

Errors should provide source location #15

Closed mgutz closed 3 years ago

mgutz commented 4 years ago

Describe the feature

Error details are currently suppressed. Logged errors should print compiler error details.

Unsure if this issue should be fixed here, in rollup-plugin-svelte-hot or in vite itself.

A Usecase

Errors are almost useless right now. For example, if a closing angle bracket is left out, the error logged is

  ParseError: Expected >
      at error$1 (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15583:20)
      at Parser$1.error (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15659:10)
      at Parser$1.eat (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15673:19)
      at tag (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:14732:13)
      at new Parser$1 (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15618:22)
      at parse$3 (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15749:21)
      at compile (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:26871:18)
      at /Users/mgutz/try/routify-mdsvex/node_modules/rollup-plugin-svelte-hot/index.js:352:22
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at async Object.transform (/Users/mgutz/try/routify-mdsvex/node_modules/svite/index.js:223:24)

There is no detail about the source causing the issue. If I patch rollup-plugin-svelte-hot in node_modules to display the actual error, the error is useful

CompileError [ParseError]: Expected >
    at error$1 (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15583:20)
    at Parser$1.error (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15659:10)
    at Parser$1.eat (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15673:19)
    at tag (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:14732:13)
    at new Parser$1 (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15618:22)
    at parse$3 (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:15749:21)
    at compile (/Users/mgutz/try/routify-mdsvex/node_modules/svelte/compiler.js:26871:18)
    at /Users/mgutz/try/routify-mdsvex/node_modules/rollup-plugin-svelte-hot/index.js:352:22
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Object.transform (/Users/mgutz/try/routify-mdsvex/node_modules/svite/index.js:223:24) {
  code: 'unexpected-eof',
  start: { line: 9, column: 18, character: 198 },
  end: { line: 9, column: 18, character: 198 },
  pos: 198,
  filename: '/Users/mgutz/try/routify-mdsvex/src/App.svelte',
  frame: ' 7: <button class="border-2 border-black p-4" >CLICK ME</button>\n' +
    ' 8: \n' +
    ' 9: <Router {routes} /\n' +
    '                      ^'
}

The source location and frame details the cause.

dominikg commented 3 years ago

Thank you for reporting this issue. svite already had an onwarn handler for rollup-plugin-svelte, unfortunately that was never called for compiler errors.

This has been added in 0.3.1. Output looks like this:

[svite] /src/App.svelte(12:78) Expected >
10: 
11: <h1>Hello {world}</h1>
12: <p>Open App.svelte in your editor and change something to see HMR in action</p
                                                                                  ^