{"record":{"id":"d82c1ec328683820","repo":"sveltejs/kit","slug":"read-failed-could-not-fetch-url-respon-d82c1e","errorCode":null,"errorMessage":"read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})","messagePattern":"read\\(\\.\\.\\.\\) failed: could not fetch (.+?) \\((.+?) (.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-netlify/files/edge.js","lineNumber":17,"sourceCode":"import { server } from '0SERVER';\n\n/**\n * We don't know the origin until we receive a request, but\n * that's guaranteed to happen before we call `read`\n * @type {string}\n */\nlet origin;\n\nconst initialized = server.init({\n\tenv: Deno.env.toObject(),\n\tread: async (file) => {\n\t\tconst url = `${origin}/${file}`;\n\t\tconst response = await fetch(url);\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(\n\t\t\t\t`read(...) failed: could not fetch ${url} (${response.status} ${response.statusText})`\n\t\t\t);\n\t\t}\n\n\t\treturn response.body;\n\t}\n});\n\n/** @type {import('@netlify/edge-functions').EdgeFunction} */\nexport default async function handler(request, context) {\n\tif (!origin) {\n\t\torigin = new URL(request.url).origin;\n\t}\n\n\t// always await initialization to prevent race condition with concurrent requests\n\tawait initialized;\n\n\treturn server.respond(request, {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-netlify/files/edge.js#L1-L35","documentation":"In Netlify Edge Functions, the SvelteKit server's read() function (used by e.g. imports of files at runtime via the $app/server read API) fetches static assets from the origin over HTTP instead of reading from disk (Deno edge runtime has no filesystem access). If the fetch to `${origin}/${file}` returns a non-OK response, this error is thrown with the URL and HTTP status.","triggerScenarios":"Calling read('path') from an edge function for a file that does not exist in the published static assets (404), or the origin returning 403/500; requesting a path outside the deployed static directory.","commonSituations":"Edge function reading a user-uploaded or generated file that was never deployed; typo in the file path; file present locally but excluded from the build output; Netlify origin briefly erroring (5xx).","solutions":["Verify the file exists in the site's published static/publish directory before calling read()","Fix the path passed to read() — it must match the deployed asset path exactly (no leading slash issues)","If the file is generated at runtime, store it in Netlify Blobs or an external store instead of relying on read()","Wrap the call in try/catch and handle non-200 responses gracefully"],"exampleFix":"// before\nconst file = await read(`${params.slug}.json`);\n// after\nlet file;\ntry {\n  file = await read(`${params.slug}.json`);\n} catch (e) {\n  throw error(404, 'Asset not found');\n}","handlingStrategy":"try-catch","validationCode":"const res = await fetch(`${origin}/${file}`, { method: 'HEAD' });\nif (!res.ok) console.warn(`Asset ${file} not deployed (HTTP ${res.status})`);","typeGuard":null,"tryCatchPattern":"try {\n  const stream = await read(filePath);\n} catch (err) {\n  if (err.message.startsWith('read(...) failed')) {\n    throw error(404, `Asset not available: ${filePath}`);\n  }\n  throw err;\n}","preventionTips":["Ensure every file passed to read() exists in the published static assets","Never call read() for runtime-generated files — use Netlify Blobs or KV instead","Log the failing URL/status from the error to distinguish 404 (missing asset) from 5xx (origin issue)"],"tags":["network","edge-functions","netlify"],"backgroundTag":"http-fetch-failed","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}