denisidoro/navi · error

Unable to get selection

Error message

Unable to get selection

What it means

`var_stdin` is a preview helper that receives a single message on stdin with three fields separated by an EOF marker: selection, query, and variable. `io::stdin().read_to_string` output is split on EOF and the first chunk is the selection; if the stream yields no first chunk (empty stdin) the `expect` panics with "Unable to get selection".

Source

Thrown at src/commands/preview/var_stdin.rs:17

use clap::Args;

use super::var;
use crate::common::shell::{self, ShellSpawnError, EOF};
use crate::prelude::*;
use std::io::{self, Read};

#[derive(Debug, Clone, Args)]
pub struct Input {}

impl Runnable for Input {
    fn run(&self) -> Result<()> {
        let mut text = String::new();
        io::stdin().read_to_string(&mut text)?;

        let mut parts = text.split(EOF);
        let selection = parts.next().expect("Unable to get selection").to_owned();
        let query = parts.next().expect("Unable to get query").to_owned();
        let variable = parts.next().expect("Unable to get variable").trim().to_owned();

        let input = var::Input {
            selection,
            query,
            variable,
        };

        input.run()?;

        if let Some(extra) = parts.next() {
            if !extra.is_empty() {
                print!("");

                let mut cmd = shell::out();
                cmd.arg(extra);
                debug!(?cmd);

View on GitHub (pinned to f7330b9ad5)

Solutions

  1. Reproduce the call manually by piping the expected payload: `printf '%s\x1e%s\x1e%s' "$SELECTION" "$QUERY" "$VARIABLE" | <bin> preview var-stdin` (adjust EOF byte to the tool's EOF constant)
  2. Check that the finder's preview command template matches the format this version expects (upgrade/downgrade mismatch)
  3. Verify the finder is passing its placeholder variables (SELECTION/QUERY/VARIABLE) into the preview command
  4. Patch the code to return a contextual error instead of panicking on missing stdin fields

Example fix

// before
let selection = parts.next().expect("Unable to get selection").to_owned();
// after
let selection = parts.next().ok_or_else(|| anyhow!("Unable to get selection from stdin payload"))?.to_owned();
Defensive patterns

Strategy: validation

Validate before calling

let text = io::stdin().read_to_string(&mut String::new())?;
// count EOF-separated fields before invoking the preview logic
let fields: Vec<&str> = text.split(EOF).collect();
if fields.len() < 3 { eprintln!("stdin payload incomplete: expected selection<EOF>query<EOF>variable"); }

Type guard

fn valid_payload(text: &str) -> bool {
    let mut parts = text.split(EOF);
    parts.next().map_or(false, |s| !s.is_empty())
        && parts.next().is_some()
        && parts.next().is_some()
}

Try / catch

let selection = text.split(EOF).next()
    .filter(|s| !s.is_empty())
    .ok_or_else(|| anyhow!("no selection in stdin payload"))?;
// expect() panics cannot be caught with try/catch semantics; guard inputs first

Prevention

When it happens

Trigger: Invoking the `var_stdin` preview command (usually from the finder preview pane) with empty or malformed stdin — the feeder process did not write the expected `<selection><EOF><query><EOF><variable>` payload.

Common situations: Finder preview integration broken after a version change (preview command signature changed); preview invoked manually/from a script without piping the payload; the finder's preview placeholder expansion failed and produced an empty string.

Related errors


AI-assisted analysis of denisidoro/navi@f7330b9ad5 (2026-09-03). Data as JSON: /api/errors/1d0b037d450e9646. Report an issue: GitHub.