{"record":{"id":"0990958e7b541fd2","repo":"BoundaryML/baml","slug":"failed-to-decode-rawptrtype-for-object","errorCode":null,"errorMessage":"Failed to decode RawPtrType for object","messagePattern":"Failed to decode RawPtrType for object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ctypes/object_args_decode.rs","lineNumber":24,"sourceCode":"    pub object: RawPtrType,\n    pub method_name: String,\n    pub kwargs: baml_types::BamlMap<String, crate::ffi::Value>,\n}\n\npub struct BamlObjectConstructorArgs {\n    pub object_type: BamlObjectType,\n    pub kwargs: baml_types::BamlMap<String, crate::ffi::Value>,\n}\n\nimpl Decode for BamlMethodArguments {\n    type From = crate::baml::cffi::BamlObjectMethodInvocation;\n\n    fn decode(from: Self::From) -> Result<Self, anyhow::Error> {\n        Ok(BamlMethodArguments {\n            object: match from.object.map(RawPtrType::decode).transpose()? {\n                Some(object) => object,\n                None => {\n                    return Err(anyhow::anyhow!(\"Failed to decode RawPtrType for object\"));\n                }\n            },\n            method_name: from.method_name,\n            kwargs: from\n                .kwargs\n                .into_iter()\n                .map(|v| {\n                    let key = match v.key {\n                        Some(crate::baml::cffi::host_map_entry::Key::StringKey(k)) => k,\n                        _ => return Err(anyhow::anyhow!(\"Key must be a string\")),\n                    };\n                    match v.value {\n                        Some(value) => Ok((key, Value::decode(value)?)),\n                        None => Err(anyhow::anyhow!(\"Failed to decode BamlValue\")),\n                    }\n                })\n                .collect::<Result<_, _>>()?,\n        })","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ctypes/object_args_decode.rs#L6-L42","documentation":"Thrown by BamlMethodArguments::decode when the `object` field is present but RawPtrType::decode fails, or — as guarded here — when the object field is absent entirely. A method call over the FFI must name a registered object; without a decodable raw pointer there is nothing to invoke the method on.","triggerScenarios":"Calling client.object_call / method invocation with no object handle set, or with a pointer ID the decoder cannot resolve (unregistered or freed handle).","commonSituations":"Invoking a method on an object after the client/runtime was shut down, passing a null handle from host code, or version-skewed bindings where handle registration changed.","solutions":["Verify a valid object handle is being passed to the method call and that it was created by the same client instance","Recreate the object (e.g. re-create the client or collector) if its handle may have been freed when the runtime shut down","Align host SDK and engine versions so handle registration/decoding is compatible"],"exampleFix":"// before (host pseudocode)\nstale_client.CallMethod(\"fn\")  // object handle gone\n\n// after\nclient = baml.Client()\nclient.CallMethod(\"fn\")","handlingStrategy":"validation","validationCode":"# host side, before invoking a method\nif obj is None or obj.handle is None:\n    raise ValueError(\"No object handle set; create the object via the client before calling methods\")","typeGuard":"function hasLiveHandle(obj) { return obj != null && typeof obj.__handle === 'number' && obj.__handle >= 0; }","tryCatchPattern":"try:\n    result = obj.CallMethod(method, kwargs)\nexcept Exception as e:\n    if \"Failed to decode RawPtrType\" in str(e):\n        obj = recreate_object(client)  # handle was stale/unregistered\n        result = obj.CallMethod(method, kwargs)\n    else:\n        raise","preventionTips":["Recreate objects after client/runtime shutdown or restart","Do not share object handles across client instances","Keep bindings and engine versions matched"],"tags":["ffi","decode","object-handle","rust"],"backgroundTag":"resource-not-found","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"}