-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Stacktrace reports wrong line number #5465
Comments
@bluwy, are we sure that this is a p3 ("An edge case that only affects very specific usage"). It was happening to me in #6372 when I was basically doing: ---
const response = await fetch(
"https://clean-dragons-hear-198-54-132-72.loca.lt/api/v1/books"
);
const data = await response.json();
const book = data.books.find((b) => b.id == id); // This is breaking cuz the fetch failed
--- Nothing too specific. I can look into it, but can you share some details about where to look (is it the |
It this an appropriate place for me to suggest this be raised to a p2? I agree with @dsomel21, it's really quite a poor onboarding experience for folks like me new to Astro. I'd love to look into helping fix this if you can give a few starting pointers 🙂 |
Sorry for the late answer, I didn't see your comment. The causes of this are quite various, so it's generally hard to pinpoint the problem and give guidance. In most cases, apart from CSS errors, the reason is source map related, either the source map that our compiler generated isn't accurate, or the source map isn't linked correctly / configured correctly. For frontmatter errors in particular, there's a bit of a special situation where the frontmatter is reparsed to give a better error message: https://github.com/withastro/astro/blob/72c6bf01fe49b331ca8ad9206a7506b15caf5b8d/packages/astro/src/vite-plugin-astro/compile.ts, which I feel might be partially responsible? I'm not sure. For CSS, generally the problem is that due to how the processing is done, we lose the original position of the style tag. We try to guess it, but it fails in most cases. I'm not 100% sure what we could do there, perhaps the compiler could return some positions as well Regarding the priority of this issue, we definitely recognize that it's a bad experience for users to have errors on the wrong lines! 😅 However, since this is not build breaking and is quite a fair amount of work, it unfortunately naturally falls behind more pressing issues. I'll bump it to p4 nonetheless, I think we have the bandwidth to fix this.. |
I looked into this over the week and it's quite a rabbithole. Things I've uncovered:
I'm testing with https://evanw.github.io/source-map-visualization/ for those who want to debug this. Overall I think the issue lies in Vite, but this also only covers the issue's original repro. I haven't checked the others yet. |
This would be very useful. I could add class name labels in development mode (related discussion: emotion-js/emotion#2172 (reply in thread)) if this works properly. related example: |
You can now use https://github.com/antfu/vite-plugin-inspect to inspect source maps issues (even in SSR code) Screen.Recording.2023-06-28.at.11.25.35.mov |
Oh schnap that is super helpful! Thanks for sharing and making it happen! |
I deubugged the sourcemaps with the inspect plugin, the insividual sourcemaps for the astro files are correct, the issue must be in the way they are applied to the stack trace or maybe combined |
Are you using the latest version of Astro? It should fix the stacktrace numbers (with Vite) and uses hi-res sourcemaps so the merged sourcemap isn't degraded. |
Edit: tested with the repro on this issue |
With my use case the line numbers are still wrong. |
@kireerik can you provide a repro for your usecase? I don't quite understand how it's related to Astro. |
Sure: Then I get incorrect line numbers with the
|
@kireerik that's not a reproduction. https://antfu.me/posts/why-reproductions-are-required |
@kireerik Sorry for the late reply. I just checked your repro, and what you're trying to do is unfortunately not something supported by Vite currently. Vite needs to transform SSR code in a different way for it to work, and that transformation affects the stacktrace generated from While Vite tries to fix it, it can only fix for thrown and caught errors. The I'm going to close this as we haven't got any new reports so far. And new ones should be created as new issues. |
What version of
astro
are you using?1.6.10
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
When accessing data that is undefined the stacktrace reports the wrong line number. When using no integrations the line number seems to be off by 1, but when using the tailwindcss integration it is off by more.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-vdxjk2?file=src/pages/index.astro
Participation
The text was updated successfully, but these errors were encountered: