{"record":{"id":"3689632106720fbe","repo":"denisidoro/navi","slug":"unable-to-get-query","errorCode":null,"errorMessage":"Unable to get query","messagePattern":"Unable to get query","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commands/preview/var_stdin.rs","lineNumber":18,"sourceCode":"use clap::Args;\n\nuse super::var;\nuse crate::common::shell::{self, ShellSpawnError, EOF};\nuse crate::prelude::*;\nuse std::io::{self, Read};\n\n#[derive(Debug, Clone, Args)]\npub struct Input {}\n\nimpl Runnable for Input {\n    fn run(&self) -> Result<()> {\n        let mut text = String::new();\n        io::stdin().read_to_string(&mut text)?;\n\n        let mut parts = text.split(EOF);\n        let selection = parts.next().expect(\"Unable to get selection\").to_owned();\n        let query = parts.next().expect(\"Unable to get query\").to_owned();\n        let variable = parts.next().expect(\"Unable to get variable\").trim().to_owned();\n\n        let input = var::Input {\n            selection,\n            query,\n            variable,\n        };\n\n        input.run()?;\n\n        if let Some(extra) = parts.next() {\n            if !extra.is_empty() {\n                print!(\"\");\n\n                let mut cmd = shell::out();\n                cmd.arg(extra);\n                debug!(?cmd);\n                cmd.spawn().map_err(|e| ShellSpawnError::new(extra, e))?.wait()?;","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/denisidoro/navi/blob/f7330b9ad5bd95b7d1a3c96d00e0a77deb589147/src/commands/preview/var_stdin.rs#L1-L36","documentation":"Same stdin protocol as [22]: the `var_stdin` preview reads `<selection><EOF><query><EOF><variable>` from stdin. The second `parts.next()` is the query; if the payload lacks a second field the `expect` panics with \"Unable to get query\".","triggerScenarios":"The stdin payload contained a selection but no query segment — i.e. only one field before EOF, or the stream ended after the first field.","commonSituations":"Finder preview template not updated to pass the QUERY placeholder; older/newer finder emitting a different number of fields; hand-crafted preview invocation missing the query.","solutions":["Confirm the finder preview command passes the QUERY placeholder in the correct position (second field, before the EOF delimiter)","Update the finder config template to match this CLI's expected `<selection><EOF><query><EOF><variable>` format","Test by piping a full three-field payload into the preview command manually","Replace the `expect` with `ok_or_else` + `?` for a graceful error"],"exampleFix":"// before\nlet query = parts.next().expect(\"Unable to get query\").to_owned();\n// after\nlet query = parts.next().ok_or_else(|| anyhow!(\"Unable to get query from stdin payload\"))?.to_owned();","handlingStrategy":"validation","validationCode":"let fields: Vec<&str> = text.split(EOF).collect();\nif fields.len() < 2 || fields[1].is_empty() {\n    eprintln!(\"stdin payload missing query field\");\n}","typeGuard":"fn has_query(text: &str) -> bool {\n    text.split(EOF).nth(1).map_or(false, |q| !q.is_empty())\n}","tryCatchPattern":"let query = text.split(EOF).nth(1)\n    .ok_or_else(|| anyhow!(\"no query in stdin payload\"))?;\n// validate payload shape before parsing rather than catching panics","preventionTips":["Ensure the finder preview template includes the QUERY placeholder as the second field","Version-lock finder config with the CLI version","Smoke-test preview invocations with a scripted payload","Log raw stdin when debugging preview panics"],"tags":["rust","panic","stdin","preview"],"backgroundTag":"malformed-stdin-payload","analyzedSha":"f7330b9ad5bd95b7d1a3c96d00e0a77deb589147","analyzedAt":"2026-09-03T13:58:22.429Z","contentChangedAt":"2026-09-03T13:58:22.429Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}