{"record":{"id":"251663c9ec39d05f","repo":"BoundaryML/baml","slug":"failed-to-get-as-url-w","errorCode":null,"errorMessage":"failed to get as url: %w","messagePattern":"failed to get as url: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_media.go","lineNumber":122,"sourceCode":"\t\treturn false, fmt.Errorf(\"failed to get is url: %w\", err)\n\t}\n\n\treturn result.(bool), nil\n}\n\nfunc (m *mediaHolder) IsBase64() (bool, error) {\n\tresult, err := raw_objects.CallMethod(m, \"is_base64\", nil)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to get is base64: %w\", err)\n\t}\n\n\treturn result.(bool), nil\n}\n\nfunc (m *mediaHolder) AsUrl() (*string, error) {\n\tresult, err := raw_objects.CallMethod(m, \"as_url\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get as url: %w\", err)\n\t}\n\n\tif result == nil {\n\t\treturn nil, nil\n\t}\n\n\tas_url, ok := result.(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for as_url: %T\", result)\n\t}\n\n\treturn &as_url, nil\n}\nfunc (m *mediaHolder) AsBase64() (*string, error) {\n\tresult, err := raw_objects.CallMethod(m, \"as_base64\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get as base64: %w\", err)\n\t}","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_media.go#L104-L140","documentation":"Wraps any error from the FFI call to the runtime's `as_url` method, which converts media content into a URL when possible. The underlying cause is preserved via %w. Note this error is distinct from AsUrl returning nil, which simply means the runtime produced no URL for this media.","triggerScenarios":"Calling AsUrl() on media whose runtime handle is invalid/freed, or when the Rust-side `as_url` method itself errors (e.g. the stored content cannot be represented as a URL).","commonSituations":"Calling AsUrl on base64 data or raw bytes that have no URL form; stale handles from released responses; client/runtime version skew.","solutions":["Check the wrapped cause with errors.Unwrap(err)","Verify media.IsUrl() is true (or IsBase64) before expecting a URL conversion; use AsBase64 for base64 media","Re-acquire the media object from a fresh BAML response","Upgrade Go client and native runtime to matching versions"],"exampleFix":"// before\nurl, err := media.AsUrl() // may fail on base64 media\n// after\nisUrl, _ := media.IsUrl()\nif isUrl {\n    url, err := media.AsUrl()\n    ...\n} else {\n    b64, err := media.AsBase64()\n    ...\n}","handlingStrategy":"fallback","validationCode":"isUrl, err := media.IsUrl()\nif err != nil || !isUrl { return nil }","typeGuard":null,"tryCatchPattern":"url, err := media.AsUrl()\nif err != nil {\n    log.Printf(\"as_url failed: %v\", err)\n    if b64, berr := media.AsBase64(); berr == nil { return useBase64(b64) }\n    return nil\n}","preventionTips":["Check IsUrl()/IsBase64() before calling the corresponding As* method","Use AsBase64 as fallback when media has no URL form","Avoid stale handles; re-fetch media from fresh responses"],"tags":["go","ffi","baml","media","url"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}