fix(sveltekit): Ensure target file exists before applying auto instrumentation #8881
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In our auto instrumentation Vite plugin for SvelteKit, we read
+(page|layout)(.server).(js|ts)
files' code to determine if we should add our wrapper to the file or not. We previously didn't check for a file id's existence before reading the file if the id matched that certain pattern, wrongly assuming that these ids would always map to actually existing files.It seems like Vite plugins such as Houdini's plugin add file ids to the build for files that actually don't exist (#8846, #8854) . When our plugin's
load
hook was called for such an id, it then tried to access and read the file which caused a build error.This patch now adds a file existence guard to ensure we simply no-op for these files.
(Wild guess: Houdini adds
load
functions for all (some?) routes so that it can do its graph QL magic under the hood. Meaning, if we no-op at build time, these functions might not be instrumented with Sentry spans. It's probably not the end of the world as errors should still be caught by thehandleError
hook. But let's see. I already cc'd the Houdini maintainers in #8846 to let them know of this).closes #8846
closes #8854