{"record":{"id":"a898f75de69455ae","repo":"withastro/astro","slug":"expectedimageoptions","errorCode":"ExpectedImageOptions","errorMessage":"Expected `getImage()` parameter to be an object. Received `${options}`.","messagePattern":"Expected `getImage\\(\\)` parameter to be an object\\. Received `(.+?)`\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/internal.ts","lineNumber":55,"sourceCode":"\t\t\terror.cause = e;\n\t\t\tthrow error;\n\t\t});\n\n\t\tif (!globalThis.astroAsset) globalThis.astroAsset = {};\n\t\tglobalThis.astroAsset.imageService = service;\n\t\treturn service;\n\t}\n\n\treturn globalThis.astroAsset.imageService;\n}\n\nexport async function getImage(\n\toptions: UnresolvedImageTransform,\n\timageConfig: AstroConfig['image'] & AstroAdapterClientConfig,\n\tlogger: AstroRuntimeLogger,\n): Promise<GetImageResult> {\n\tif (!options || typeof options !== 'object') {\n\t\tthrow new AstroError({\n\t\t\t...AstroErrorData.ExpectedImageOptions,\n\t\t\tmessage: AstroErrorData.ExpectedImageOptions.message(JSON.stringify(options)),\n\t\t});\n\t}\n\tif (typeof options.src === 'undefined') {\n\t\tthrow new AstroError({\n\t\t\t...AstroErrorData.ExpectedImage,\n\t\t\tmessage: AstroErrorData.ExpectedImage.message(\n\t\t\t\toptions.src,\n\t\t\t\t'undefined',\n\t\t\t\tJSON.stringify(options),\n\t\t\t),\n\t\t});\n\t}\n\n\tif (isImageMetadata(options)) {\n\t\tthrow new AstroError(AstroErrorData.ExpectedNotESMImage);\n\t}","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/assets/internal.ts#L37-L73","documentation":"`getImage(options, imageConfig)` (packages/astro/src/assets/internal.ts:53) requires its first argument to be an options object. If it receives a primitive, null, or undefined (`typeof options !== 'object'`), it throws `ExpectedImageOptions` with the received value serialized into the message.","triggerScenarios":"Calling `getImage('hero.png')`, `getImage(undefined)` (e.g. a variable that failed to initialize), or passing the output of a function that returns a string instead of an options object.","commonSituations":"Refactoring from string-based helpers; data-driven rendering where a map lookup returns undefined; passing already-resolved URL strings from an older Astro snippet.","solutions":["Pass an options object: `getImage({ src, width, height })`.","If options come from dynamic data, guard with `if (!options || typeof options !== 'object')` and fail with your own message.","Check for typos like `getImage(src)` where a variable shadows the intended options object."],"exampleFix":"// before\nconst img = await getImage(heroImagePath);\n\n// after\nconst img = await getImage({ src: heroImagePath, width: 800, height: 600 });","handlingStrategy":"type-guard","validationCode":"if (!options || typeof options !== 'object') {\n  throw new Error(`getImage expected an options object, got ${typeof options}`);\n}","typeGuard":"import type { UnresolvedImageTransform } from 'astro';\n\nfunction isImageOptions(value: unknown): value is UnresolvedImageTransform {\n  return typeof value === 'object' && value !== null;\n}","tryCatchPattern":null,"preventionTips":["Type helper functions' return values as options objects, not strings.","Lint against bare-string arguments to getImage."],"tags":["images","getimage","api-usage"],"backgroundTag":"invalid-function-arguments","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-09-09T03:35:40.650Z","contentChangedAt":"2026-09-09T03:35:40.650Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}