Skip to content
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

adapter-cloudflare-workers: Throws KVError if asked for a nonexisting asset #9288

Closed
tv42 opened this issue Mar 2, 2023 · 1 comment
Closed

Comments

@tv42
Copy link

tv42 commented Mar 2, 2023

Describe the bug

It seems when deployed to Cloudflare Workers, requests for non-existing assets get a 500 internal error, not a 404.
The page says "Error 1101 Worker threw exception".
wrangler tail shows

GET https://example.com/blah/_app/immutable/assets/REDACTED.css - Exception Thrown @ 3/2/2023, 1:15:01 PM
✘ [ERROR]   Error: KVError: could not find blah/_app/immutable/assets/REDACTED.css in your content namespace

(the "REDACTED" is literal, not my editing; see below)

I've observed this two ways:

  1. ablocking browser extension changing request URL from _app/immutable/assets/GoogleAnalytics.HASH.css to _app/immutable/assets/REDACTED.css
  2. old versions of app still live in browser fetching assets that no longer exist after a deploy

What seems to be happening is that @sveltejs/adapter-cloudflare-workers function get_asset_from_kv calls getAssetFromKV from @cloudflare/kv-asset-handler without catching exceptions, and that function is documented to throw KVError on not found.

It seems like it should catch KVError and throw error(404, {...}) in its place.

https://github.com/cloudflare/kv-asset-handler#getassetfromkv

async function get_asset_from_kv(req, env, context, map = mapRequestToAsset) {

Reproduction

https://github.com/tv42/sveltekit-issue9288-cloudflare-adapter-404

Logs

GET https://example.com/blah/_app/immutable/assets/REDACTED.css - Exception Thrown @ 3/2/2023, 1:15:01 PM
✘ [ERROR]   Error: KVError: could not find blah/_app/immutable/assets/REDACTED.css in your content namespace

System Info

Production is Cloudflare Workers. Dev is


  System:
    OS: Linux 6.1 NixOS 22.11 (Raccoon) 22.11 (Raccoon)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 46.64 GB / 62.60 GB
    Container: Yes
    Shell: 5.1.16 - /nix/store/96ky1zdkpq871h2dlk198fz0zvklr1dr-bash-5.1-p16/bin/bash
  Binaries:
    Node: 16.19.1 - /nix/store/i9xar2vndv4qy0w9jzcscfj05jqgigyk-nodejs-16.19.1/bin/node
    npm: 8.19.3 - /nix/store/i9xar2vndv4qy0w9jzcscfj05jqgigyk-nodejs-16.19.1/bin/npm
  Browsers:
    Firefox: 110.0
  npmPackages:
    @sveltejs/adapter-cloudflare: ^2.1.0 => 2.1.0
    @sveltejs/adapter-cloudflare-workers: ^1.0.6 => 1.0.6
    @sveltejs/kit: ^1.9.2 => 1.9.2
    svelte: ^3.55.1 => 3.55.1
    vite: ^4.1.4 => 4.1.4

Severity

annoyance

Additional Information

No response

@ghostdevv
Copy link
Member

Going to close this as I believe it was fixed by #4276, let me know if I was wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants