{"record":{"id":"b131595599a91d85","repo":"Kuberwastaken/claurst","slug":"source-settings-json-must-be-a-json-object","errorCode":null,"errorMessage":"source settings.json must be a JSON object","messagePattern":"source settings\\.json must be a JSON object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-rust/crates/core/src/import_config.rs","lineNumber":307,"sourceCode":"\nstruct SettingsPreviewOutcome {\n    preview_fields: Vec<PreviewField>,\n    imported_fields: Vec<String>,\n    skipped_fields: Vec<String>,\n    imported_count: usize,\n    replaced_count: usize,\n    kept_count: usize,\n    skipped_count: usize,\n}\n\nfn map_settings_preview(\n    source: &Value,\n    current: &Value,\n    target: &mut Settings,\n) -> Result<SettingsPreviewOutcome> {\n    let source_obj = source\n        .as_object()\n        .ok_or_else(|| anyhow!(\"source settings.json must be a JSON object\"))?;\n\n    let mut preview_fields = Vec::new();\n    let mut imported_fields = Vec::new();\n    let mut skipped_fields = Vec::new();\n    let mut imported_count = 0;\n    let mut replaced_count = 0;\n    let mut kept_count = 0;\n    let mut skipped_count = 0;\n\n    if source_obj.contains_key(\"model\") {\n        preview_fields.push(PreviewField {\n            name: \"model\".to_string(),\n            action: PreviewAction::Skip,\n            reason: Some(\"model is not imported to keep the current session and default model unchanged\".to_string()),\n        });\n        skipped_fields.push(\"model\".to_string());\n        skipped_count += 1;\n    } else {","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/core/src/import_config.rs#L289-L325","documentation":"Thrown by `map_settings_preview` (part of `prepare_import_with_paths`) when the source settings.json parsed as a serde_json Value but is not a JSON object. The import path requires the top-level source document to be an object so its fields can be iterated for the preview; arrays, strings, numbers, or null are rejected with this message.","triggerScenarios":"Pointing the import command at a settings.json whose top level is an array, string, number, boolean, or null — e.g. a file containing `[...]`, a JSON-lines dump, or a wrongly exported settings file.","commonSituations":"Importing a file that is actually a JSON array of settings snapshots; importing an export log or wrapped payload like {\"settings\": {...}} saved incorrectly as `[\"{...}\"]`; a corrupted/partially-written settings file; grabbing the wrong file (not settings.json) that still parses as JSON.","solutions":["Inspect the source file: ensure its top level is `{ ... }`, not an array or scalar.","If it is a wrapped export, unwrap to the inner object before importing.","Re-export settings from the source tool so settings.json is a proper object.","In callers, validate `value.is_object()` before invoking the import/preview APIs."],"exampleFix":"// before\nlet v: Value = serde_json::from_str(&raw)?;\nprepare_import_with_paths(&v, ...)?; // v = [ ... ] -> error\n\n// after\nlet v: Value = serde_json::from_str(&raw)?;\nif !v.is_object() {\n    anyhow::bail!(\"settings source is not an object\");\n}\nprepare_import_with_paths(&v, ...)?;","handlingStrategy":"type-guard","validationCode":"let v: serde_json::Value = serde_json::from_str(&raw)?;\nif !v.is_object() {\n    anyhow::bail!(\"settings source is not a JSON object\");\n}","typeGuard":"fn is_json_object(v: &serde_json::Value) -> bool { v.is_object() }","tryCatchPattern":"match prepare_import_with_paths(&source, ...) {\n    Ok(preview) => apply(preview),\n    Err(e) if e.to_string().contains(\"must be a JSON object\") => {\n        // inspect/repair the source file, then retry\n        inspect_and_fix_source(path)?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check the source file's top level is { ... } before importing.","Unwrap wrapped exports (e.g. [{...}] or {\"settings\":{...}}) to the plain object.","Validate with serde_json::Value::is_object at load time.","Re-export settings from the source tool if the file looks corrupted."],"tags":["json","validation","import","settings","config"],"backgroundTag":"config-type-mismatch","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}