risingwavelabs/risingwave · error · ExprError

Context not found

Error message

Context {0} not found

What it means

ExprError::Context(&'static str) indicates that an expected evaluation/planning context object was not found; the interpolated string names which context is missing. Expression evaluation sometimes depends on ambient context (e.g. timezone config, session information, lambda context) that must be installed by the caller before evaluation.

Solutions

  1. Install/provide the required context (e.g. timezone/session context) before evaluating the expression.
  2. Fix the context key/name used in the lookup to match what was registered.
  3. In embedded usage, initialize the same context builders the standard engine entry points use.

Example fix

// before
let ctx = contexts.get("tz").ok_or(ExprError::Context("tz"))?;
// after
let ctx = contexts.entry("tz").or_insert_with(TimeZoneContext::default); // or ensure setup_eval_context(&mut contexts) first
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the context is registered before evaluation
if contexts.get("tz").is_none() {
    contexts.insert("tz".into(), Box::new(TimeZoneContext::default()));
}

Type guard

fn has_context(ctxs: &Contexts, key: &'static str) -> bool {
    ctxs.get(key).is_some()
}

Try / catch

// Missing context is a setup bug: fail fast with a clear message
if let Some(ExprError::Context(name)) = err.downcast_ref::<ExprError>() {
    panic!("evaluation context '{name}' was not initialized");
}

Prevention

When it happens

Trigger: Evaluating an expression that needs a registered context (e.g. timezone context for time functions) in a driver that never set it up; looking up a named context in a context registry with a key that wasn't inserted.

Common situations: Embedding the expression engine without wiring session/config context, tests calling `eval` directly without the standard context setup, refactors renaming context keys while old lookups remain.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/4e41c1a8886a674c. Report an issue: GitHub.

Appendix: source

Thrown at src/expr/core/src/error.rs:102

        #[backtrace]
        ArrayError,
    ),

    #[error("More than one row returned by {0} used as an expression")]
    MaxOneRow(&'static str),

    /// TODO: deprecate in favor of `Function`
    #[error(transparent)]
    Internal(
        #[from]
        #[backtrace]
        anyhow::Error,
    ),

    #[error("not a constant")]
    NotConstant,

    #[error("Context {0} not found")]
    Context(&'static str),

    #[error("field name must not be null")]
    FieldNameNull,

    #[error("too few arguments for format()")]
    TooFewArguments,

    #[error(
        "null value in column \"{col_name}\" of relation \"{table_name}\" violates not-null constraint"
    )]
    NotNullViolation {
        col_name: Box<str>,
        table_name: Box<str>,
    },

    #[error("invalid state: {0}")]
    InvalidState(String),

View on GitHub (pinned to 6469eb736d)