{"record":{"id":"7943a9e6fa0b60fc","repo":"xai-org/x-algorithm","slug":"not-implemented-to-thrift-for-safetyresult","errorCode":null,"errorMessage":"Not implemented: to_thrift for SafetyResult","messagePattern":"Not implemented: to_thrift for SafetyResult","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"visibility-filtering-client/models.rs","lineNumber":192,"sourceCode":"                        32 => SafetyResultReason::GoreAndViolenceHighPrecision,\n                        _ => SafetyResultReason::Episodic,\n                    });\n                }\n                Some(2) => {\n                    action = Action::from_thrift(proto);\n                }\n                _ => {\n                    proto.skip(field.field_type).unwrap();\n                }\n            }\n            proto.read_field_end().unwrap();\n        }\n        proto.read_struct_end().unwrap();\n        SafetyResult { reason, action }\n    }\n\n    fn to_thrift(&self, _proto: &mut dyn TOutputProtocol) {\n        panic!(\"Not implemented: to_thrift for SafetyResult\")\n    }\n}\n\nimpl MValCodec for Action {\n    fn thrift_type() -> TType {\n        TType::Struct\n    }\n\n    fn from_thrift(proto: &mut dyn TInputProtocol) -> Self {\n        proto.read_struct_begin().unwrap();\n        let mut result = Action::NotEvaluated;\n        loop {\n            let field = proto.read_field_begin().unwrap();\n            if field.field_type == TType::Stop {\n                break;\n            }\n            match field.id {\n                Some(1) => {","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/visibility-filtering-client/models.rs#L174-L210","documentation":"SafetyResult implements only the Thrift decode half of MValCodec; to_thrift panics because serialization was never needed for this type. The panic documents an intentional hole in the codec implementation rather than a runtime condition.","triggerScenarios":"Serializing a SafetyResult (reason + action fields) to Thrift: writing it to a log/mval sink, sending it over a Thrift service, or a generic encode path / round-trip test that invokes to_thrift.","commonSituations":"New feature code starts emitting SafetyResult over the wire or into storage; generic codec utilities that encode every MValCodec type; test harnesses that verify symmetry between from_thrift and to_thrift.","solutions":["Avoid encoding SafetyResult; consume it via from_thrift only.","Implement to_thrift mirroring the decoder: write 'reason' and 'action' fields with the same field ids/types the reader expects.","Serialize an equivalent protobuf type if one exists instead of the Thrift codec."],"exampleFix":"// before\nfn to_thrift(&self, _proto: &mut dyn TOutputProtocol) {\n    panic!(\"Not implemented: to_thrift for SafetyResult\")\n}\n\n// after: mirror the reader's field ids (1: reason, 2: action)\nfn to_thrift(&self, proto: &mut dyn TOutputProtocol) {\n    proto.write_struct_begin(&TStructIdentifier::new(\"SafetyResult\")).unwrap();\n    self.reason.write_field(proto, 1);\n    self.action.write_field(proto, 2);\n    proto.write_field_stop().unwrap();\n    proto.write_struct_end().unwrap();\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"trait WriteCodec { fn to_thrift(&self, p: &mut dyn TOutputProtocol); }\nfn encode<T: WriteCodec>(v: &T, p: &mut dyn TOutputProtocol) { v.to_thrift(p); }\n// SafetyResult: encode via this fn is a compile error until implemented","tryCatchPattern":"let r = std::panic::catch_unwind(|| sr.to_thrift(proto));\nif r.is_err() { /* log and serialize the protobuf equivalent instead */ }","preventionTips":["Use capability traits (WriteCodec/ReadCodec) instead of one MValCodec with panicking halves.","Avoid generic 'encode anything' utilities over codec impls.","Add unit tests that assert which types are encodeable."],"tags":["rust","thrift","serialization","codec","visibility-filtering","not-implemented"],"backgroundTag":"thrift-unimplemented-serializer","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}