{"record":{"id":"35a07377bffd4331","repo":"BoundaryML/baml","slug":"failed-to-create-media-w","errorCode":null,"errorMessage":"failed to create media: %w","messagePattern":"failed to create media: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_constructors.go","lineNumber":44,"sourceCode":"\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for collector creation: %T\", ptr)\n\t}\n\n\treturn as_collector, nil\n}\n\nfunc (r *BamlRuntime) newMediaFromUrl(mediaType MediaType, url string, mimeType *string) (media, error) {\n\tkwargs, err := serde.EncodeMapEntries(map[string]any{\n\t\t\"mime_type\": mimeType,\n\t\t\"url\":       url,\n\t}, \"media constructor args\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to encode kwargs: %w\", err)\n\t}\n\n\tptr, err := raw_objects.NewRawObject(r.runtime, mediaType.objectType(), kwargs)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create media: %w\", err)\n\t}\n\n\tas_media, ok := ptr.(media)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for media creation: %T\", ptr)\n\t}\n\n\treturn as_media, nil\n}\n\nfunc (r *BamlRuntime) NewImageFromUrl(url string, mimeType *string) (Image, error) {\n\treturn r.newMediaFromUrl(MediaType_Image, url, mimeType)\n}\n\nfunc (r *BamlRuntime) NewAudioFromUrl(url string, mimeType *string) (Audio, error) {\n\treturn r.newMediaFromUrl(MediaType_Audio, url, mimeType)\n}\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_constructors.go#L26-L62","documentation":"After encoding kwargs, newMediaFromUrl calls raw_objects.NewRawObject to create the media object in the Rust runtime. If the runtime rejects the request, the underlying error is wrapped as 'failed to create media'. This is the main failure path when constructing image/audio/pdf/video objects from a URL.","triggerScenarios":"Calling NewImageFromUrl, NewAudioFromUrl, NewPDFFromUrl or NewVideoFromUrl with arguments the runtime rejects — e.g. an invalid/unparseable url, a mime_type string the runtime cannot accept, or a runtime-level object allocation failure.","commonSituations":"Passing an empty string as url, a malformed URL the runtime's parser rejects, an unsupported mime type value, or a corrupted native runtime that fails to allocate cffi objects.","solutions":["Inspect the wrapped inner error (%w chain) for the runtime's specific complaint","Validate the url is non-empty and well-formed (scheme + host) before calling","Ensure mimeType is a supported media type string (e.g. image/png, application/pdf) or nil for auto-detection","Confirm the native BAML runtime loaded correctly and matches the Go SDK version"],"exampleFix":"// before\nimg, err := runtime.NewImageFromUrl(\"\", nil) // runtime rejects empty url\n// after\nif u, perr := url.Parse(rawURL); perr != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid media url: %q\", rawURL)\n}\nimg, err := runtime.NewImageFromUrl(rawURL, nil)","handlingStrategy":"validation","validationCode":"func validateUrlForMedia(rawURL string) error {\n    if rawURL == \"\" { return errors.New(\"url must not be empty\") }\n    u, err := url.Parse(rawURL)\n    if err != nil { return fmt.Errorf(\"unparseable url: %w\", err) }\n    if u.Scheme != \"http\" && u.Scheme != \"https\" { return errors.New(\"url must be http(s)\") }\n    if u.Host == \"\" { return errors.New(\"url missing host\") }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := validateUrlForMedia(u); err != nil { return err }\nmedia, err := runtime.NewPDFFromUrl(u, &mime)\nif err != nil {\n    var inner error\n    errors.As(err, &inner) // inspect wrapped runtime cause\n    return fmt.Errorf(\"media creation rejected: %w\", err)\n}","preventionTips":["Validate URLs (non-empty, http/https, host present) before constructing media","Use supported mime type strings or nil for auto-detection","Match base64/url media type to the constructor you call (image vs pdf vs audio)"],"tags":["go","baml-runtime","media","construction-failure"],"backgroundTag":"invalid-argument-value","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"}