nushell/nushell · error

Selector cannot be none to convert

Error message

Selector cannot be none to convert

What it means

Panic in NuSelector::into_polars: consumes the wrapper with self.selector.expect('Selector cannot be none to convert'), and into_expr() chains into_polars to build Expr::Selector. If the selector is None (default-constructed or produced by the Deserialize impl), converting it panics. This is the consuming conversion site for empty selectors values.

Source

Thrown at crates/nu_plugin_polars/src/dataframe/values/nu_selector/mod.rs:62

    }
}

impl From<Selector> for NuSelector {
    fn from(selector: Selector) -> Self {
        Self::new(Some(selector))
    }
}

impl NuSelector {
    fn new(selector: Option<Selector>) -> Self {
        Self {
            id: Uuid::new_v4(),
            selector,
        }
    }

    pub fn into_polars(self) -> Selector {
        self.selector.expect("Selector cannot be none to convert")
    }

    pub fn into_expr(self) -> NuExpression {
        NuExpression::from(Expr::Selector(self.into_polars()))
    }

    pub fn to_value(&self, span: Span) -> Result<Value, ShellError> {
        // Convert selector to a displayable string representation
        Ok(Value::string(format!("{:?}", self.selector), span))
    }
}

impl Cacheable for NuSelector {
    fn cache_id(&self) -> &Uuid {
        &self.id
    }

    fn to_cache_value(&self) -> Result<PolarsPluginObject, ShellError> {

View on GitHub (pinned to 8e03210652)

Solutions

  1. Always construct from a real Selector: NuSelector::from(selector)
  2. Branch on the inner Option before conversion instead of assuming Some
  3. Maintainer option: return Result from into_polars or make deserialize produce a valid Selector

Example fix

// before
let expr = nu_selector.into_expr(); // panics when selector is None

// after: explicit empty check before conversion
let selector = nu_selector.selector.ok_or_else(|| {
    ShellError::Generic(GenericError::new("Selector is empty", "cannot convert a default/deserialized selector", span))
})?;
let expr = NuExpression::from(Expr::Selector(selector));
Defensive patterns

Strategy: type-guard

Validate before calling

let selector = match nu_selector.selector {
    Some(s) => s,
    None => return Err(ShellError::Generic(GenericError::new("Selector is empty", "cannot convert a default/deserialized selector", span))),
};
let expr = NuExpression::from(Expr::Selector(selector));

Type guard

fn into_polars_checked(s: NuSelector) -> Option<polars::prelude::Selector> {
    s.selector
}

Prevention

When it happens

Trigger: Calling into_polars or into_expr on a NuSelector from NuSelector::default() or one that round-tripped through serialization; serde defaults yielding empty selectors later converted to expressions.

Common situations: Passing selector expressions through the plugin boundary and reusing them; tests using default() selectors that are then converted.

Related errors


AI-assisted analysis of nushell/nushell@8e03210652 (2026-08-17). Data as JSON: /api/errors/45662cc31c029fdd. Report an issue: GitHub.