{"record":{"id":"1aa5f4c7defa800b","repo":"libnyanpasu/clash-nyanpasu","slug":"filter-merge-target-item-is-not-a-mapping-item","errorCode":null,"errorMessage":"filter `merge` target item is not a mapping, item kept","messagePattern":"filter `merge` target item is not a mapping, item kept","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"backend/nyanpasu-config/src/runtime/executor/overlay.rs","lineNumber":235,"sourceCode":"                        return item;\n                    }\n                    match &action {\n                        FilterAction::Expr(expr) => match runner.eval_item_expr(expr, &item) {\n                            Ok(next) => next,\n                            Err(error) => {\n                                logs.push(StepLogEntry::warn(format!(\n                                    \"filter `expr` failed, item kept: {error}\"\n                                )));\n                                item\n                            }\n                        },\n                        FilterAction::Override(replacement) => (*replacement).clone(),\n                        FilterAction::Merge(merge) => {\n                            // Legacy panics on non-mapping items (merge.rs:163\n                            // `as_mapping_mut().unwrap()`); never-fail keeps\n                            // the item instead (spec §13 #15).\n                            if item.as_object_arc().is_none() {\n                                logs.push(StepLogEntry::warn(\n                                    \"filter `merge` target item is not a mapping, item kept\",\n                                ));\n                                return item;\n                            }\n                            deep_merge_value(Some(&item), merge)\n                        }\n                        FilterAction::Remove(paths) => remove_from_item(item, paths, logs),\n                    }\n                })\n                .collect()\n        }\n        _ => {\n            logs.push(StepLogEntry::warn(\"invalid filter value, skipped\"));\n            items\n        }\n    }\n}\n","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/nyanpasu-config/src/runtime/executor/overlay.rs#L217-L253","documentation":"When a filter's `merge` action applies to an item, the item must be a mapping; if it is a scalar or array the merge cannot proceed. Unlike the legacy implementation (which panicked via as_mapping_mut().unwrap()), this executor keeps the item and logs a warning instead.","triggerScenarios":"A `when` predicate matches a non-mapping item in the filtered sequence and the action is `merge`.","commonSituations":"Filtering lists that mix scalars and objects (e.g. rules as plain strings) with a merge action intended for object items.","solutions":["Restrict the `when` predicate so it only matches mapping items (e.g. check item.type or another object-only field)","Change the action from `merge` to `override` if replacing the item wholesale is acceptable","Convert sequence items into mappings before filtering","Ignore the warning if keeping unmatched non-mapping items is intended"],"exampleFix":"// before\nwhen: \"true\"\nmerge: { extra: 1 }\n// after\nwhen: \"item.name != null\"\nmerge: { extra: 1 }","handlingStrategy":"validation","validationCode":"// in the `when` predicate, restrict to mapping items:\n// when: \"item.name != null\"\nlet matched: Vec<_> = items.iter().filter(|i| i.as_object_arc().is_some()).collect();\nassert!(!matched.is_empty(), \"merge action requires mapping items\");","typeGuard":"fn item_is_mapping(v: &ConfigValue) -> bool { v.as_object_arc().is_some() }","tryCatchPattern":null,"preventionTips":["Write `when` predicates that only match object items for merge actions","Avoid mixing scalars and objects in lists targeted by merge filters","Keep step logging enabled to notice kept-but-unmerged items"],"tags":["config","filter","merge","type-mismatch"],"backgroundTag":"config-type-mismatch","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}