{"record":{"id":"cde3d676e1891907","repo":"libnyanpasu/clash-nyanpasu","slug":"filter-expr-failed-item-kept-error","errorCode":null,"errorMessage":"filter `expr` failed, item kept: {error}","messagePattern":"filter `expr` failed, item kept: (.+?)","errorType":"console","errorClass":"StepLogEntry","httpStatus":null,"severity":"warning","filePath":"backend/nyanpasu-config/src/runtime/executor/overlay.rs","lineNumber":223,"sourceCode":"                .into_iter()\n                .map(|item| {\n                    let hit = match runner.eval_item_predicate(when, &item) {\n                        Ok(hit) => hit,\n                        Err(error) => {\n                            logs.push(StepLogEntry::warn(format!(\n                                \"filter `when` failed, treated as false: {error}\"\n                            )));\n                            false\n                        }\n                    };\n                    if !hit {\n                        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                        }","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/nyanpasu-config/src/runtime/executor/overlay.rs#L205-L241","documentation":"During overlay filter application, the `expr` transform (FilterAction::Expr) failed to evaluate for an item. Unlike the `when` failure, the item is KEPT unchanged and a warning is logged. This fail-open behavior means a broken expression leaves the original item in the config rather than dropping it.","triggerScenarios":"apply_filter calls runner.eval_item_expr(expr, &item) for a FilterAction::Expr rule and the script runner returns Err — syntax errors, references to non-existent item fields, or runtime exceptions inside the expression.","commonSituations":"A rewrite expression written for a prior schema (field renamed/removed); an expression with a typo or wrong return type; items with heterogeneous shapes where some lack the fields the expression mutates.","solutions":["Fix the `expr` expression in the overlay filter rule (inspect the interpolated {error} in the warning log)","Confirm every field the expression reads exists on all filtered items","If the expression should replace the item wholesale and failure is unacceptable, validate the expression before applying the overlay","Use FilterAction::Override instead of Expr if the value is static and needs no evaluation"],"exampleFix":"// before\n{\"expr\": \"item.name = 'x'\"}\n// after (correct assignment/transform syntax)\n{\"expr\": \"item.name := 'x'\"}","handlingStrategy":"validation","validationCode":"fn valid_expr(expr: &str, sample: &ConfigValue) -> bool { ScriptRunner::default().eval_item_expr(expr, sample).is_ok() }","typeGuard":null,"tryCatchPattern":"match runner.eval_item_expr(expr, &item) { Ok(next) => next, Err(e) => { log::warn!(\"expr failed: {e}\"); item } }","preventionTips":["Validate `expr` transforms against a sample item before applying overlays","Keep expressions schema-version-aware; update them when item fields change","Prefer FilterAction::Override for static values that need no evaluation"],"tags":["config","overlay","scripting","filter"],"backgroundTag":"invalid-argument-value","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"}