Skip to content

async errors report the wrong location during SSR #10779

@lazy-detourer

Description

@lazy-detourer

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions