{"record":{"id":"68738abe18b6db25","repo":"BoundaryML/baml","slug":"image-is-not-a-url","errorCode":null,"errorMessage":"Image is not a URL","messagePattern":"Image is not a URL","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/image.js","lineNumber":68,"sourceCode":"     */\n    static async fromUrlAsync(url) {\n        const response = await fetch(url);\n        const blob = await response.blob();\n        return BamlImage.fromBlob(blob);\n    }\n    /**\n     * Check if the image is stored as a URL\n     */\n    isUrl() {\n        return this.type === 'url';\n    }\n    /**\n     * Get the URL of the image if it's stored as a URL\n     * @throws Error if the image is not stored as a URL\n     */\n    asUrl() {\n        if (!this.isUrl()) {\n            throw new Error('Image is not a URL');\n        }\n        return this.content;\n    }\n    /**\n     * Get the base64 data and media type if the image is stored as base64\n     * @returns [base64Data, mediaType]\n     * @throws Error if the image is not stored as base64\n     */\n    asBase64() {\n        if (this.type !== 'base64') {\n            throw new Error('Image is not base64');\n        }\n        return [this.content, this.mediaType || ''];\n    }\n    /**\n     * Convert the image to a JSON representation\n     */\n    toJSON() {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/image.js#L50-L86","documentation":"JavaScript client state guard: asUrl() was called on a BamlImage whose internal type is 'base64', not 'url'. BamlImage is a tagged union of url/base64 representations and each accessor demands its own tag; the guard fires before returning content so callers never misinterpret base64 payload data as a URL.","triggerScenarios":"Calling image.asUrl() on an Image instance created from base64 data.","commonSituations":"Handling image outputs from vision/LLM calls that return base64 and assuming a URL; mixing up Image.fromUrl vs Image.fromBase64 instances.","solutions":["Check image.isUrl() before calling asUrl().","Use asBase64() when the image stores base64 data.","Construct the image with Image.fromUrl when URL access is needed."],"exampleFix":"// before\nconst url = image.asUrl(); // throws for base64 image\n// after\nconst url = image.isUrl() ? image.asUrl() : null;","handlingStrategy":"type-guard","validationCode":"if (image.isUrl()) { /* safe to call asUrl */ }","typeGuard":"function isUrlImage(image) { return typeof image.isUrl === 'function' && image.isUrl(); }","tryCatchPattern":"try {\n  const url = image.asUrl();\n} catch (e) {\n  if (e.message === 'Image is not a URL') { /* fall back to asBase64 */ }\n  else throw e;\n}","preventionTips":["Check isUrl() before asUrl().","Keep construction (fromUrl/fromBase64) consistent with downstream accessors."],"tags":["typescript","image","media","state-error"],"backgroundTag":"incompatible-source-type","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}