{"record":{"id":"508080735c9f2bac","repo":"influxdata/influxdb","slug":"unexpected-content-in-valueexpr","errorCode":null,"errorMessage":"Unexpected content in ValueExpr","messagePattern":"Unexpected content in ValueExpr","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/predicate/src/lib.rs","lineNumber":345,"sourceCode":"            right: _,\n        }) = &expr\n            && let Expr::Column(inner) = left.as_ref()\n            && inner.name == VALUE_COLUMN_NAME\n        {\n            return Ok(Self { expr });\n        }\n        Err(expr)\n    }\n}\n\nimpl ValueExpr {\n    /// Returns a new [`Expr`] with the reference to the `_value`\n    /// column replaced with the specified column name\n    pub fn replace_col(&self, name: &str) -> Expr {\n        if let Expr::BinaryExpr(BinaryExpr { left: _, op, right }) = &self.expr {\n            binary_expr(name.as_expr(), *op, right.as_ref().clone())\n        } else {\n            unreachable!(\"Unexpected content in ValueExpr\")\n        }\n    }\n}\n\nimpl From<ValueExpr> for Expr {\n    fn from(value_expr: ValueExpr) -> Self {\n        value_expr.expr\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    use data_types::{MAX_NANO_TIME, MIN_NANO_TIME};\n    use datafusion::prelude::{col, lit};\n\n    #[test]\n    fn test_default_predicate_is_empty() {","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/core/predicate/src/lib.rs#L327-L363","documentation":"`ValueExpr::replace_col` panics with unreachable!() when the wrapped expr is not an `Expr::BinaryExpr`. ValueExpr is a typed wrapper guaranteeing the inner expr is a BinaryExpr whose left side is the `_value` column (enforced by TryFrom<Expr>), so this only fires if the invariant was bypassed — e.g. a ValueExpr constructed via unsafe/private means or the struct definition changed.","triggerScenarios":"Calling replace_col on a ValueExpr whose internal expr was mutated or constructed outside TryFrom<Expr> (bypassing the `_value`-column BinaryExpr check), e.g. `ValueExpr { expr: col(\"a\") }` via struct literal within the crate.","commonSituations":"Crate-internal refactors that construct ValueExpr directly instead of via try_from; tests hand-building ValueExpr; version changes altering Expr variants.","solutions":["Only create ValueExpr via TryFrom<Expr> / expr.try_into() and handle the Err variant instead of unwrapping into a bad ValueExpr","Confirm the expr passed through try_from was not modified after conversion","If you construct ValueExpr within the crate, reuse TryFrom rather than struct-literal initialization","Replace the panic with an Option/Result return to make the invariant failure recoverable"],"exampleFix":"// before\nlet ve = ValueExpr { expr: some_expr }; // bypasses invariant\nlet rewritten = ve.replace_col(\"field\");\n// after\nlet ve = ValueExpr::try_from(some_expr)\n    .map_err(|_| anyhow::anyhow!(\"expr is not a _value binary expr\"))?;\nlet rewritten = ve.replace_col(\"field\");","handlingStrategy":"type-guard","validationCode":"fn can_replace_col(expr: &Expr, value_col: &str) -> bool {\n    matches!(expr, Expr::BinaryExpr(b) if matches!(b.left.as_ref(), Expr::Column(c) if c.name == value_col))\n}","typeGuard":"fn as_value_expr(expr: Expr) -> Option<ValueExpr> {\n    ValueExpr::try_from(expr).ok()\n}","tryCatchPattern":"// Rust: conversion is fallible, handle Err instead of unwrapping\nlet ve = match ValueExpr::try_from(expr) {\n    Ok(ve) => ve,\n    Err(orig) => return Err(anyhow!(\"not a _value binary expr: {orig:?}\")),\n};","preventionTips":["Always construct ValueExpr via TryFrom<Expr>, never via struct literal","Do not mutate the inner expr after conversion","Add debug_assert! in replace_col documenting the BinaryExpr invariant","Keep Expr-building helpers close to the ValueExpr definition so invariants stay in sync"],"tags":["panic","invariant","expression","predicate"],"backgroundTag":"internal-invariant-violation","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}