Skip to content

chore: remove unnecessary try/catch - #12762

Merged
benmccann merged 1 commit into
mainfrom
try-catch
Oct 9, 2024
Merged

benmccann merged 1 commit into
mainfrom
try-catch

Conversation

@benmccann

Copy link
Copy Markdown
Member

Vite should handle an error here, so we shouldn't need our own handling

@changeset-bot

changeset-bot Bot commented Oct 7, 2024

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a6548fe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@teemingc

teemingc commented Oct 7, 2024 •

Copy link
Copy Markdown
Member

Do you suppose these should fix these weird stackblitz errors?

stackblitz error

I'd approve but I don't have the information on whether Vite will handle the error here.

@benmccann

Copy link
Copy Markdown
Member Author

No, I doubt it will change that

If I get a chance later I can hardcode an error in this block locally to confirm that Vite handles it

@teemingc

teemingc commented Oct 9, 2024 •

Copy link
Copy Markdown
Member

I was curious and tested the hardcoded error you mentioned to try in the vite block itself. It seems it moves the error from just the browser to the browser and server (which seems better?). Other errors through Svelte files etc are unaffected. I'm in favour of this.

With try catch block:
error page

Without try catch block:
error page and error in console

@benmccann

Copy link
Copy Markdown
Member Author

awesome. thanks!

@benmccann
benmccann merged commit a612292 into main Oct 9, 2024
@benmccann
benmccann deleted the try-catch branch October 9, 2024 03:20
teemingc added a commit that referenced this pull request Nov 19, 2026
Fixes #17650

The dev asset middleware decodes every request pathname before deciding
whether it names a static asset. Invalid percent escapes therefore throw
before application routing and become Vite 500 error responses,
including for malformed image URLs such as `/%%7BimgPath%7D`.

The early asset handler introduced in
#5686 remains necessary to keep
public assets out of Vite's transform middleware.
#12762 removed its broad catch
because Vite already handles unexpected errors; restoring that catch, or
copying the later handler's catch, would still produce a 500.

Catch only pathname decoding failures and return a small 400 response
before continuing through the middleware chain. This also prevents these
invalid paths from reaching the later dev decoder. URL parsing,
filesystem failures, asset serving, case checks, and base-path handling
retain their existing behavior. Preview already guards decoding and
falls through to the runtime's malformed-URI handling, so it needs no
change. Unlike a forgiving decoder or broad middleware catch, this does
not pass malformed paths downstream or misclassify genuine server errors
as client errors.

The behavior covers document and subresource requests while preserving
valid encoded paths and percent escapes in query strings.

- [Ported
reproduction](https://www.sveltelab.dev/#code=N4IgzgTgxiBcoBMCWECmUAuB7CBPOoAhgA7EB0AFhgLYA2BIAZkrag1FgHYardhwgAPAEIEWTLmKoABFToA%2BADqdBc2tNqFOAcwC8ikLwNLOijKtSEEJs2cHVUGQtKgVCEMI-0gArhkYAtAAcBtIA9DYYdg5O0pyEDt4AbkioAO7EOFEgLlw83N5pSAgYFLoIqClQqAFFJRQANNJInEgYSIS0AWBQnai6AIyhEcq25jHO8YkGPAAeGN29rKEc3LwY3j19w5FmAKRgSai0PADWbZSWCHuj5mEUV5GCAEZYCLjSCIRO3UcnqOcFsQ0LQsFYAl8nN4KFgjhBjLc7MgktIwBhcKxvMgwMRNLhYLk1nxjAc-mcLq93ntBGFkU8wpTcCYaWoTCAAL7shogCBYPyofjwEDINCYHD4IUAajxfIwZEOxx4DGYrHYeXWgqEPQgSGIGA0Wj0MzACNM7WomQg%2BvRUmkwGkABlCLhZQAFXnEMDSdnSRi86jSADkZDCABIbQLAwBuUZm1j6%2B2uFgINCcb0Ep0uvzurCe6S6aSh4G5sAACgAlDGVGFtbqMDZOMAAAKpioQFwUZOpivs5QcrkgSXEQjaVDyslsIUqyegVb5DCa1QDeQAdWOHAc0mw0gAyhOANJtFnL5SCYjyABqSDAbWkgmcFDQjGhGAwntgYRrE7IFSStPEYBhICxgKv8P6VP%2BUCAYCNKEPIW5YNIaBWFuDyfOIPgONw3xIFwNLnn2nJEQOw5QKcI5jgAVmAXDKiwM4gHOGoCMAiIgFMqAGASBiAgEAwAOwAGwAKwAAwGA0bFwjeXBcdIBiiWQilDCAklmgYwJIEk3ycXAW4QD4qBqbYIARnJBjUG8PjLKpbFIBaWQmnprHqdkADEtBIM85kgCGkBQGEnnPGELQVLMZDURJiLuUFYQAFQ%2BX50CBV58UGLcXJsbWepOQSLljAYv4%2BSkPCfJUUWuQYzw%2BMmxVtDI1W1bZlUgMClSpGkdWlW1KTpBVBWtWgw5oD5oE8AEgKorgnBQNIAA%2Bc3SOgMJBoG-VRNkrjoKco0ThNt5gNNs0AGTHaie1bWR0gBAEC6rMw2jSCGd1cA9EU0aYzUDZdpywGk3yuLtio1JNh0zdIp3ncDAQ-ddt09K9SCPc9COcG91FcHD-0YIDIAZcZ2S-gAIqgUicBUM2pLldrRQYTZjag1FhFYJA8BAASEH4WA%2BUESlKetJn0xOTPAXpBgAMxkAMUsC9kQvA0zJU1LiPjaC0vzAz5-FkJLKkEyZDM%2BcJZDCdr4uywYDMww8ZE%2BQAegALGQgn819G0zJIApQDqer2y7inm27JlKzzOvO%2BlZq9pwUf9tyL1o0j720VO9FqkSC4sWxqDzLwCDUwYoYkMQYTxw9AuMVgFr0RAADyeq4Zw1P5e74AYDqmByW3hn43ZM20D4FRyQA2pb0ASfJIBK2Q92JwuBgALrKDHnLclPM-aGQGcp6qQpMXwAj2Za%2Bos3qqDtn6ldBvL-xMyfbMc1z0bKIfWR2lD-yTT6F8BoG188CLbQwhKyfq0ByVo34VGYJwVAABhRGj0v7%2BiDMAqsyhs5HzKowTmJxMEtFgfA0szcVZq0bgSEerkGaAkIbTHGldiDVzru0LgYA8o0LMAZaBLDpCEN9PRDi3pyz5l2O7Da04OLylxG0UsYQh5hEUPIxQ88wjljIC0KA-cKhlkDJwN4qAAD6lkEDWUjIIgA-NIHw5NUBQNQAgaQBIu6cUqhgTKphnF3zPgSDxEAKzRXZOWW4i9o6VkIpyIAA)
— request `/%%7BimgPath%7D` while running in dev mode.

<!--
svelte-triage-bot:feedback-baseline:af9ba601bc93d4df09052edff9fb18620dd9bd85
-->

---------

Co-authored-by: svelte-triage-bot <[email protected]>
Co-authored-by: Tee Ming <[email protected]>

This branch was successfully deployed

2 active deployments
Preview – kit-default-template — a6548fef Deployed Oct 7, 2024 by vercel[bot]
Preview – kit-svelte-dev — a6548fef Deployed Oct 7, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants