If I generate a sveltekit app skeleton with
npm create svelte@latest lineno
cd lineno
npm install
And then create a hooks handler script with a trivial handler generates an error myself, I get the wrong line number (4 instead of 2):
export const handle = async ({ event, resolve }) => {
console.log(new Error("My error").stack)
return await resolve(event);
}
Error: My error
at Object.handle (/erikor/Documents/Business/lineno/src/hooks.server.js:4:15)
(Interestingly, actual code errors caught by the runtime report the correct line numbers, as one would expect.)
Why is the stack trace line number different when I create a new error compared to when there is an error in my code causing the error to be thrown? And is there a way to get the correct line numbers?