{"record":{"id":"1ada7adf7c617986","repo":"libnyanpasu/clash-nyanpasu","slug":"filter-when-failed-treated-as-false-error","errorCode":null,"errorMessage":"filter `when` failed, treated as false: {error}","messagePattern":"filter `when` failed, treated as false: (.+?)","errorType":"console","errorClass":"StepLogEntry","httpStatus":null,"severity":"warning","filePath":"backend/nyanpasu-config/src/runtime/executor/overlay.rs","lineNumber":210,"sourceCode":"                FilterAction::Override(replacement)\n            } else if let Some(merge) = actions\n                .get(\"merge\")\n                .filter(|value| value.as_object_arc().is_some())\n            {\n                FilterAction::Merge(merge)\n            } else if let Some(ConfigValue::Array(paths)) = actions.get(\"remove\") {\n                FilterAction::Remove(paths)\n            } else {\n                logs.push(StepLogEntry::warn(\"invalid filter: no action\"));\n                return items;\n            };\n            items\n                .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                        },","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/nyanpasu-config/src/runtime/executor/overlay.rs#L192-L228","documentation":"During overlay filter application, the `when` predicate (a script expression) failed to evaluate for an item. The library treats the predicate as false, meaning the item is filtered out, and logs a warning instead of aborting the whole overlay step. This keeps a single bad predicate from breaking the entire config pipeline.","triggerScenarios":"apply_filter calls runner.eval_item_predicate(when, &item) and the script runner returns Err — e.g. the `when` expression references an undefined field, has a syntax error, uses an unsupported operator, or throws at runtime for a particular item.","commonSituations":"A user-authored overlay filter rule with a typo in the `when` expression; a `when` predicate written against a different schema version where the referenced item field no longer exists; script expressions evaluated against items whose shape varies (missing keys).","solutions":["Fix the `when` expression syntax/fields referenced by the filter rule in the overlay document","Check the StepLogEntry warning text for the underlying script error ({error} interpolates the actual cause)","Verify the predicate only references fields that exist on every item being filtered","Test the expression with eval_item_predicate directly on a sample item"],"exampleFix":"// before: references possibly-missing field\n{\"when\": \"item.port > 1000\"}\n// after: guard against missing field\n{\"when\": \"'port' in item and item.port > 1000\"}","handlingStrategy":"validation","validationCode":"fn valid_when(when: &str, sample: &ConfigValue) -> bool { ScriptRunner::default().eval_item_predicate(when, sample).is_ok() }","typeGuard":null,"tryCatchPattern":"match runner.eval_item_predicate(when, &item) { Ok(hit) => hit, Err(e) => { log::warn!(\"when failed: {e}\"); false } }","preventionTips":["Reference only fields guaranteed on every item in `when` predicates","Test overlay filter expressions on sample items before deploying","Guard optional fields with existence checks inside the expression"],"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"}