{"record":{"id":"2a75544e366a8156","repo":"cross-rs/cross","slug":"failed-to-serialize-crosstoml-as-object","errorCode":null,"errorMessage":"failed to serialize CrossToml as object","messagePattern":"failed to serialize CrossToml as object","errorType":"error_code","errorClass":"eyre::ErrReport","httpStatus":null,"severity":"error","filePath":"src/cross_toml.rs","lineNumber":220,"sourceCode":"                unused.clone().into_iter().collect::<Vec<_>>().join(\", \")\n            ))?;\n        }\n\n        Ok((cfg, unused))\n    }\n\n    /// Merges another [`CrossToml`] into `self` and returns a new merged one\n    pub fn merge(self, other: CrossToml) -> Result<CrossToml> {\n        type ValueMap = serde_json::Map<String, serde_json::Value>;\n\n        fn to_map<S: Serialize>(s: S) -> Result<ValueMap> {\n            if let Some(obj) = serde_json::to_value(s)\n                .wrap_err(\"could not convert CrossToml to serde_json::Value\")?\n                .as_object()\n            {\n                Ok(obj.clone())\n            } else {\n                eyre::bail!(\"failed to serialize CrossToml as object\");\n            }\n        }\n\n        fn from_map<D: DeserializeOwned>(map: ValueMap) -> Result<D> {\n            let value = serde_json::to_value(map)\n                .wrap_err(\"could not convert ValueMap to serde_json::Value\")?;\n            serde_json::from_value(value)\n                .wrap_err(\"could not deserialize serde_json::Value to CrossToml\")\n        }\n\n        // merge 2 objects. y has precedence over x.\n        fn merge_objects(x: &mut ValueMap, y: &ValueMap) -> Option<()> {\n            // we need to iterate over both keys, so we need a full deduplication\n            let keys: BTreeSet<String> = x.keys().chain(y.keys()).cloned().collect();\n            for key in keys {\n                let in_x = x.contains_key(&key);\n                let in_y = y.contains_key(&key);\n                if !in_x && in_y {","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/cross-rs/cross/blob/8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27/src/cross_toml.rs#L202-L238","documentation":"`CrossToml::to_map` serializes the TOML config into a `serde_json::Value` and expects it to be a JSON object (map). If the serialized value is not an object (e.g. an array or scalar), it fails, because the merge machinery (`merge`) can only combine map-shaped configs.","triggerScenarios":"Calling `merge` on a `CrossToml` whose serialization does not yield a JSON object — typically an internal invariant violation when the TOML deserialized into a non-table top-level shape.","commonSituations":"A cross.toml whose top level is not a table (rare, usually only via programmatic construction or corrupted config), or a bug in the merge pipeline passing a non-map value.","solutions":["Ensure the cross.toml top level is a TOML table (key/value sections), not an array or bare value.","If constructing CrossToml programmatically, build it as a map/struct that serializes to an object.","Inspect the chained error (\"could not convert CrossToml to serde_json::Value\") for the underlying serialization failure."],"exampleFix":"// before (invalid top-level TOML)\n[[config]]\nkey = \"value\"\n// after\n[config]\nkey = \"value\"","handlingStrategy":"try-catch","validationCode":"// ensure top-level cross config is a table\nif !raw_toml.trim_start().starts_with('[') && raw_toml.contains('=') && !raw_toml.contains('\\n[') { /* likely scalar top-level, reject */ }","typeGuard":null,"tryCatchPattern":"match CrossToml::merge(...) {\n    Ok(t) => t,\n    Err(e) => { eprintln!(\"config merge failed: {e:?>}\"); return Err(e); }\n}","preventionTips":["Keep cross.toml top level a TOML table with named sections.","Round-trip programmatic configs through to_map in unit tests.","Log the full eyre report chain to see the underlying serialization cause."],"tags":["serialization","toml","config","merge"],"backgroundTag":"json-serialization-failed","analyzedSha":"8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27","analyzedAt":"2026-09-13T15:10:43.988Z","contentChangedAt":"2026-09-13T15:10:43.988Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}