{"record":{"id":"61b780a5a905d3d3","repo":"spacedriveapp/spacedrive","slug":"failed-to-serialize","errorCode":null,"errorMessage":"Failed to serialize {}: {}","messagePattern":"Failed to serialize (.+?): (.+?)","errorType":"exception","errorClass":"CoreError","httpStatus":null,"severity":"error","filePath":"core/src/domain/resource_registry.rs","lineNumber":237,"sourceCode":"\t\tinventory::submit! {\n\t\t\t$crate::domain::resource_registry::ResourceInventoryEntry {\n\t\t\t\tbuild: || {\n\t\t\t\t\t$crate::domain::resource_registry::ResourceRegistration::new(\n\t\t\t\t\t\t<$resource as $crate::domain::resource::Identifiable>::resource_type(),\n\t\t\t\t\t\t<$resource as $crate::domain::resource::Identifiable>::sync_dependencies(),\n\t\t\t\t\t\t|db, dep_type, dep_id| {\n\t\t\t\t\t\t\tBox::pin(async move {\n\t\t\t\t\t\t\t\t<$resource as $crate::domain::resource::Identifiable>::route_from_dependency(db, dep_type, dep_id).await\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\t|db, ids| {\n\t\t\t\t\t\t\tBox::pin(async move {\n\t\t\t\t\t\t\t\tlet resources = <$resource as $crate::domain::resource::Identifiable>::from_ids(db, ids).await?;\n\t\t\t\t\t\t\t\tresources\n\t\t\t\t\t\t\t\t\t.into_iter()\n\t\t\t\t\t\t\t\t\t.map(|r| {\n\t\t\t\t\t\t\t\t\t\tserde_json::to_value(&r).map_err(|e| {\n\t\t\t\t\t\t\t\t\t\t\t$crate::common::errors::CoreError::Other(anyhow::anyhow!(\n\t\t\t\t\t\t\t\t\t\t\t\t\"Failed to serialize {}: {}\",\n\t\t\t\t\t\t\t\t\t\t\t\t<$resource as $crate::domain::resource::Identifiable>::resource_type(),\n\t\t\t\t\t\t\t\t\t\t\t\te\n\t\t\t\t\t\t\t\t\t\t\t))\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t.collect::<$crate::common::errors::Result<Vec<_>>>()\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\t<$resource as $crate::domain::resource::Identifiable>::no_merge_fields(),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n}\n\n#[cfg(test)]","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/domain/resource_registry.rs#L219-L255","documentation":"Produced inside the resource-registration macro in core/src/domain/resource_registry.rs:237 when serde_json::to_value(&resource) fails for a resource fetched through Identifiable::from_ids. The macro serializes every resource of a registered type into JSON for the resource-resolution pipeline; if the resource's Serialize impl returns an error (not a JSON-shape mismatch, an actual serialization error), the whole from_ids batch fails with CoreError::Other wrapping this message.","triggerScenarios":"Registering a resource type (via the registry macro) whose Serialize impl can fail: HashMap with non-string-serializable keys, custom Serialize::serialize returning Err, f64::NAN with serde_json arbitrary-precision features, or a field type whose to_value errors at runtime.","commonSituations":"Adding a new Identifiable resource with a hand-written Serialize; changing a domain struct so a map key type stops serializing to a JSON string; unit tests only ever checking Debug, never exercising to_value.","solutions":["Reproduce directly: `serde_json::to_value(&sample_resource)` in a unit test for the failing resource type; the serde error names the exact field.","Fix the Serialize impl or the offending field (most often: convert HashMap<NonStringKey, _> keys to Strings, or guard NaN/Infinity floats).","Add a regression test `assert!(serde_json::to_value(&resource).is_ok())` next to the resource definition so registration-time serialization stays covered."],"exampleFix":"// before (key type fails to serialize as JSON object key)\nlet meta: HashMap<i64, String> = fetch_meta();\n\n// after\nlet meta: HashMap<String, String> = fetch_meta()\n    .into_iter()\n    .map(|(k, v)| (k.to_string(), v))\n    .collect();","handlingStrategy":"try-catch","validationCode":"// register-time smoke test: prove every resource serializes before shipping\n#[test]\nfn resource_serializes_to_json() {\n    let r = SampleResource::fixture();\n    assert!(serde_json::to_value(&r).is_ok(), \"Identifiable resource must serialize\");\n}","typeGuard":null,"tryCatchPattern":"// catch per resource batch and report the type instead of a generic opaque error\nlet values = serde_json::to_value(&resource).map_err(|e| {\n    CoreError::Other(anyhow::anyhow!(\"resource {} failed JSON roundtrip: {e}\", std::any::type_name::<R>()))\n});","preventionTips":["Avoid non-string map keys in resource structs.","Prefer derived Serialize over hand-written impls for registered resources.","Keep a unit test asserting to_value works for each registered Identifiable type."],"tags":["serde","resource-registry","serialization","macro"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}