{"record":{"id":"45662cc31c029fdd","repo":"nushell/nushell","slug":"selector-cannot-be-none-to-convert","errorCode":null,"errorMessage":"Selector cannot be none to convert","messagePattern":"Selector cannot be none to convert","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/nu_plugin_polars/src/dataframe/values/nu_selector/mod.rs","lineNumber":62,"sourceCode":"    }\n}\n\nimpl From<Selector> for NuSelector {\n    fn from(selector: Selector) -> Self {\n        Self::new(Some(selector))\n    }\n}\n\nimpl NuSelector {\n    fn new(selector: Option<Selector>) -> Self {\n        Self {\n            id: Uuid::new_v4(),\n            selector,\n        }\n    }\n\n    pub fn into_polars(self) -> Selector {\n        self.selector.expect(\"Selector cannot be none to convert\")\n    }\n\n    pub fn into_expr(self) -> NuExpression {\n        NuExpression::from(Expr::Selector(self.into_polars()))\n    }\n\n    pub fn to_value(&self, span: Span) -> Result<Value, ShellError> {\n        // Convert selector to a displayable string representation\n        Ok(Value::string(format!(\"{:?}\", self.selector), span))\n    }\n}\n\nimpl Cacheable for NuSelector {\n    fn cache_id(&self) -> &Uuid {\n        &self.id\n    }\n\n    fn to_cache_value(&self) -> Result<PolarsPluginObject, ShellError> {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/nushell/nushell/blob/8e03210652f3c48c4521cec982d96e4cb6c67181/crates/nu_plugin_polars/src/dataframe/values/nu_selector/mod.rs#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing selector expressions through the plugin boundary and reusing them; tests using default() selectors that are then converted.","solutions":["Always construct from a real Selector: NuSelector::from(selector)","Branch on the inner Option before conversion instead of assuming Some","Maintainer option: return Result from into_polars or make deserialize produce a valid Selector"],"exampleFix":"// before\nlet expr = nu_selector.into_expr(); // panics when selector is None\n\n// after: explicit empty check before conversion\nlet selector = nu_selector.selector.ok_or_else(|| {\n    ShellError::Generic(GenericError::new(\"Selector is empty\", \"cannot convert a default/deserialized selector\", span))\n})?;\nlet expr = NuExpression::from(Expr::Selector(selector));","handlingStrategy":"type-guard","validationCode":"let selector = match nu_selector.selector {\n    Some(s) => s,\n    None => return Err(ShellError::Generic(GenericError::new(\"Selector is empty\", \"cannot convert a default/deserialized selector\", span))),\n};\nlet expr = NuExpression::from(Expr::Selector(selector));","typeGuard":"fn into_polars_checked(s: NuSelector) -> Option<polars::prelude::Selector> {\n    s.selector\n}","tryCatchPattern":null,"preventionTips":["Always build NuSelector from a parsed Selector value","Pattern-match on the inner Option instead of calling into_polars/into_expr blindly"],"tags":["nushell","polars","rust","panic","expect","selector","conversion"],"backgroundTag":"empty-value-after-deserialize","analyzedSha":"8e03210652f3c48c4521cec982d96e4cb6c67181","analyzedAt":"2026-08-17T16:24:07.527Z","contentChangedAt":"2026-08-17T16:24:07.527Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}