{"record":{"id":"9ef9ffa9d0a08d1c","repo":"withastro/astro","slug":"failedtofetchremoteimagedimensions","errorCode":"FailedToFetchRemoteImageDimensions","errorMessage":"Failed to get the dimensions for ${url}.","messagePattern":"Failed to get the dimensions for (.+?)\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/utils/remoteProbe.ts","lineNumber":23,"sourceCode":"import { imageMetadata } from './metadata.js';\nimport { fetchWithRedirects } from './redirectValidation.js';\n\ntype RemoteImageConfig = Pick<AstroConfig['image'], 'domains' | 'remotePatterns'>;\n\n/**\n * Infers the dimensions of a remote image by streaming its data and analyzing it progressively until sufficient metadata is available.\n *\n * @param {string} url - The URL of the remote image from which to infer size metadata.\n * @param {RemoteImageConfig} [imageConfig] - Optional image config used to validate remote allowlists.\n * @return {Promise<Omit<ImageMetadata, 'src' | 'fsPath'>>} Returns a promise that resolves to an object containing the image dimensions metadata excluding `src` and `fsPath`.\n * @throws {AstroError} Thrown when the fetching fails or metadata cannot be extracted.\n */\nexport async function inferRemoteSize(\n\turl: string,\n\timageConfig?: RemoteImageConfig,\n): Promise<Omit<ImageMetadata, 'src' | 'fsPath'>> {\n\tif (!URL.canParse(url)) {\n\t\tthrow new AstroError({\n\t\t\t...AstroErrorData.FailedToFetchRemoteImageDimensions,\n\t\t\tmessage: AstroErrorData.FailedToFetchRemoteImageDimensions.message(url),\n\t\t});\n\t}\n\n\tconst allowlistConfig = imageConfig\n\t\t? {\n\t\t\t\tdomains: imageConfig.domains ?? [],\n\t\t\t\tremotePatterns: imageConfig.remotePatterns ?? [],\n\t\t\t}\n\t\t: undefined;\n\n\tif (!allowlistConfig) {\n\t\tconst parsedUrl = new URL(url);\n\t\tif (!['http:', 'https:'].includes(parsedUrl.protocol)) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...AstroErrorData.FailedToFetchRemoteImageDimensions,\n\t\t\t\tmessage: AstroErrorData.FailedToFetchRemoteImageDimensions.message(url),","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/assets/utils/remoteProbe.ts#L5-L41","documentation":"First guard in inferRemoteSize(): URL.canParse(url) returned false, so Astro rejects the input before any network call. Code FailedToFetchRemoteImageDimensions, message embeds the offending url. This is purely an input-validation failure, not a network problem.","triggerScenarios":"Passing inferSize on a remote Image whose src is not a valid absolute URL — undefined, an empty string, a relative path, or a malformed string that the URL constructor rejects. Reached when an <Image src=\"…\" inferSize /> or getImage({ src, inferSize: true }) points at a remote string.","commonSituations":"Reading src from a CMS field that was empty/undefined; building the URL from an env var that was not set; passing a relative path like '/images/x.png' (which belongs in public/) instead of an absolute https URL; a typo stripping the scheme.","solutions":["Confirm the src is a fully-qualified absolute URL with scheme, e.g. `https://cdn.example.com/img.png`.","Guard the CMS-supplied value: skip the Image or fall back when the field is empty.","If the asset is local, move it into src/assets and import it, or put it in public/ and drop inferSize.","Log the value right before render to catch undefined/empty inputs."],"exampleFix":"// before\n<Image src={post.coverUrl} inferSize alt=\"…\" />  // coverUrl is undefined\n\n// after\n{post.coverUrl && <Image src={post.coverUrl} inferSize alt=\"…\" />}","handlingStrategy":"validation","validationCode":"function isAbsoluteUrl(v: unknown): v is string {\n  return typeof v === 'string' && URL.canParse(v) && /^https?:/.test(v);\n}\n// before render:\nif (!isAbsoluteUrl(src)) { /* fall back / skip inferSize */ }","typeGuard":"function isRemoteUrl(v: unknown): v is string {\n  return typeof v === 'string' && URL.canParse(v) && ['http:','https:'].includes(new URL(v).protocol);\n}","tryCatchPattern":null,"preventionTips":["Never pass undefined/empty CMS fields to inferSize.","Validate URLs at the data layer, not in the template.","Use a typed schema (zod) for CMS image fields."],"tags":["assets","remote-images","validation","url"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}