{"record":{"id":"c1c8f00ded352d52","repo":"libnyanpasu/clash-nyanpasu","slug":"filter-expr-failed-item-removed-error","errorCode":null,"errorMessage":"filter expr failed, item removed: {error}","messagePattern":"filter expr failed, item removed: (.+?)","errorType":"console","errorClass":"StepLogEntry","httpStatus":null,"severity":"warning","filePath":"backend/nyanpasu-config/src/runtime/executor/overlay.rs","lineNumber":167,"sourceCode":"\nfn apply_filter(\n    items: Vec<ConfigValue>,\n    filter: &ConfigValue,\n    runner: &dyn ScriptRunner,\n    logs: &mut Vec<StepLogEntry>,\n) -> Vec<ConfigValue> {\n    match filter {\n        // Sequence of filters: composable multi-pass (merge.rs do_filter).\n        ConfigValue::Array(filters) => filters\n            .iter()\n            .fold(items, |acc, sub| apply_filter(acc, sub, runner, logs)),\n        // String: Lua boolean predicate; eval error removes the item (parity).\n        ConfigValue::String(expr) => items\n            .into_iter()\n            .filter(|item| match runner.eval_item_predicate(expr, item) {\n                Ok(keep) => keep,\n                Err(error) => {\n                    logs.push(StepLogEntry::warn(format!(\n                        \"filter expr failed, item removed: {error}\"\n                    )));\n                    false\n                }\n            })\n            .collect(),\n        ConfigValue::Object(actions) => {\n            let Some(ConfigValue::String(when)) = actions.get(\"when\") else {\n                logs.push(StepLogEntry::warn(\"invalid filter: missing `when`\"));\n                return items;\n            };\n            // Action selection mirrors the legacy match-arm order and typed\n            // guards (merge.rs:122-231): an action whose guard fails falls\n            // through to the next arm; when nothing matches, the `_` arm\n            // warns once without evaluating `when` per item.\n            enum FilterAction<'a> {\n                Expr(&'a str),\n                Override(&'a ConfigValue),","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/nyanpasu-config/src/runtime/executor/overlay.rs#L149-L185","documentation":"This warning is logged by `apply_filter` when a Lua string predicate passed for a filter step fails to evaluate for an item (`runner.eval_item_predicate` returns Err). Following legacy parity semantics, a predicate evaluation error removes the item from the list rather than keeping it — the step succeeds overall, but the failed item is dropped and the error recorded in the step log.","triggerScenarios":"Using a `filter` step whose expression is a Lua string and the script raises a runtime error for an item — undefined variable/function in the expression, comparing incompatible types (e.g. number vs string), or accessing a missing item field without guarding.","commonSituations":"Filter expressions copied from examples referencing fields absent in the user's subscription items; Lua syntax/type errors after schema changes to item fields; hand-edited profile enhance scripts with typos.","solutions":["Read the logged `{error}` in the step log to see the exact Lua failure and fix the expression accordingly.","Guard field access in the predicate (e.g. `return item.name ~= nil and item.name:find('x') ~= nil`) so missing fields don't error.","Test the Lua expression against a representative item before shipping the enhance chain.","If items should be kept on error rather than removed, restructure the filter to return a safe default (`true`) on missing data."],"exampleFix":"// before: errors when 'region' is missing\nfilter: return item.region == 'HK'\n// after: nil-safe predicate\nfilter: return item.region ~= nil and item.region == 'HK'","handlingStrategy":"validation","validationCode":"-- nil-safe Lua predicate template\n-- return type(item) == 'table' and item.region ~= nil and item.region == 'HK'","typeGuard":null,"tryCatchPattern":"// inspect step log for filter failures\nfor entry in result.log.iter().filter(|e| e.level == Warn) {\n    if entry.message.starts_with(\"filter expr failed\") {\n        eprintln!(\"filter error: {}\", entry.message);\n    }\n}","preventionTips":["Guard every field access in Lua predicates with nil checks","Test expressions against representative subscription items before shipping","Prefer tolerant predicates (default to keeping the item) over strict comparisons","Keep filter scripts in version control so regressions are traceable"],"tags":["lua","filter","overlay","config"],"backgroundTag":"script-evaluation-failed","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"}