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

async errors report the wrong location during SSR #10779

Open
lazy-detourer opened this issue Sep 25, 2023 · 4 comments
Open

async errors report the wrong location during SSR #10779

lazy-detourer opened this issue Sep 25, 2023 · 4 comments

Comments

@lazy-detourer
Copy link

Describe the bug

I've been suffering from incorrect error locations for a long time and was very excited about #10769 and version 1.25.1.
However, it seems to be about server rendering and some IDE, and not related to errors in code executed in hooks.server.js.

Even in a stackblitz environment, the phenomenon is well reproduced. In the project I linked there is only a 2 line difference, but it is not consistent at all. Sometimes it is smaller than it actually is, but most of the time they report a larger number.

I keep the asynchronous infinite loop executed in hooks.server.js residing on the server like a daemon. And the values calculated by the infinite loop are frequently referenced and output by several pages of svelte. I don't think this is an overly unusual structure.

In that infinite loop, errors will occur frequently, and I want to quickly find their location. Currently I am having a very hard time.

Since I'm having a really hard time, I'd like to know at least a temporary solution.
For example, in #10769, I checked the following link: https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/server/utils.js#L98
I found this to be of great help in making this temporary fix. I hope there is something similar for my case. I am not skilled enough to find it myself. Please help me.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-wsaice?file=jsconfig.json

hooks.server.js:

console.log('run: hooks.server.js (line 1)');

setTimeout(() => {
	// Dummy code to place the error location in the middle of the file.  (line 4)

	console.log('error soon  (line 6)');
}, 3000);

setTimeout(() => {
	console.log('<--- line number 10', new Error().stack);
	throw new Error('<---- line number 11');
}, 4000);

setTimeout(() => {
	console.log('dummy'); //(line 15)

	console.log('dummy'); //(line 17)

	console.log('dummy'); //(line 19)
}, 10000);

package.json:

"@sveltejs/kit": "1.25.1"

Logs

run: hooks.server.js (line 1)
page option:  { prerender: false, ssr: false }
error soon  (line 6)
<--- line number 10 Error
    at Timeout.eval (/home/projects/sveltejs-kit-template-default-wsaice/src/hooks.server.js:12:37)
    at listOnTimeout (node:internal/timers:62:4448)
    at processTimers (node:internal/timers:62:5285)
    at <anonymous> (https://sveltejskittemplatedefaultwsai-dctb.w-credentialless.staticblitz.com/blitz.d6c42aca.js:334:292836)
    at <anonymous> (https://sveltejskittemplatedefaultwsai-dctb.w-credentialless.staticblitz.com/blitz.d6c42aca.js:334:293145)
Error: <---- line number 11
    at Timeout.eval (/home/projects/sveltejs-kit-template-default-wsaice/src/hooks.server.js:13:8)
    at listOnTimeout (node:internal/timers:62:4448)
    at processTimers (node:internal/timers:62:5285)
    at <anonymous> (https://sveltejskittemplatedefaultwsai-dctb.w-credentialless.staticblitz.com/blitz.d6c42aca.js:334:292836)
    at <anonymous> (https://sveltejskittemplatedefaultwsai-dctb.w-credentialless.staticblitz.com/blitz.d6c42aca.js:334:293145)

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.20.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
    pnpm: 8.6.10 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
    @sveltejs/kit: 1.25.1 => 1.25.1 
    svelte: ^4.0.5 => 4.2.0 
    vite: ^4.4.2 => 4.4.9

Severity

annoyance

Additional Information

No response

@gtm-nayan
Copy link
Contributor

@lzdetourer Is this specific to using setTimeout? If so there's not much really do for that or any other asynchronous errors since those can't be intercepted by SvelteKit or Vite.

The errors need to be caught by the framework somehow to fix the stack and that can't happen if they're thrown asynchronously without being awaited.

@lazy-detourer
Copy link
Author

@lzdetourer Is this specific to using setTimeout? If so there's not much really do for that or any other asynchronous errors since those can't be intercepted by SvelteKit or Vite.

The errors need to be caught by the framework somehow to fix the stack and that can't happen if they're thrown asynchronously without being awaited.

It is used in setTimeout and async/await infinite loop.
But since it's so painful to me, I don't mind changing the method as long as I can find the location of the error. For example, it is enough to know the exact location of the Error object generated in the try-catch statement inside async.

@lazy-detourer

This comment was marked as duplicate.

@lazy-detourer

This comment was marked as duplicate.

@eltigerchino eltigerchino changed the title The error in hooks.server.js still reports the wrong location. async errors reports the wrong location during SSR Oct 9, 2024
@eltigerchino eltigerchino changed the title async errors reports the wrong location during SSR async errors report the wrong location during SSR Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants