GitoxideLabs/gitoxide · error

parser must have set some object value

Error message

parser must have set some object value

What it means

In the `gix explain` revision output, `revision_name()` expects either a parsed ref name or an object-id prefix to have been recorded by the argument parser. If neither was set, the `.expect()` panics with this message — an internal invariant violation in the CLI, not a library error.

Solutions

  1. Provide a valid revision argument (ref name, OID, or prefix) to the explain command.
  2. Fix the parser so every accepted input sets `oid_prefix` when `ref_name` is not derivable.
  3. Replace the `.expect()` with a fallback message like `"<unknown>"` to avoid panics on bad input.

Example fix

// before
self.oid_prefix.expect("parser must have set some object value").to_string().into()

// after
self.oid_prefix.map(|oid| oid.to_string().into()).unwrap_or_else(|| "<no object>".into())
Defensive patterns

Strategy: type-guard

Validate before calling

// before calling explain
if revision_arg.trim().is_empty() {
    bail!("revision argument required");
}

Type guard

fn has_resolvable_name(p: &ExplainState) -> bool {
    p.ref_name.is_some() || p.oid_prefix.is_some()
}

Try / catch

// panic-based; guard instead
if !has_resolvable_name(&state) {
    bail!("input resolved to neither ref nor object");
}

Prevention

When it happens

Trigger: Invoking the explain command path where the input was resolved to neither a ref name nor an OID prefix, i.e. the parser filled neither `ref_name` nor `oid_prefix`.

Common situations: Passing an empty or malformed revision spec to the explain command; a regression where object resolution silently skipped setting `oid_prefix`.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/19483b5597186f46. Report an issue: GitHub.

Appendix: source

Thrown at gitoxide-core/src/repository/revision/explain.rs:52

    fn new(out: &'a mut impl std::io::Write) -> Self {
        Explain {
            out,
            call: 0,
            ref_name: None,
            oid_prefix: None,
            has_implicit_anchor: false,
            err: None,
        }
    }
    fn prefix(&mut self) -> Result<(), Exn> {
        self.call += 1;
        write!(self.out, "{:02}. ", self.call).ok();
        Ok(())
    }
    fn revision_name(&self) -> BString {
        self.ref_name.clone().unwrap_or_else(|| {
            self.oid_prefix
                .expect("parser must have set some object value")
                .to_string()
                .into()
        })
    }
}

impl delegate::Revision for Explain<'_> {
    fn find_ref(&mut self, name: &BStr) -> Result<(), Exn> {
        self.prefix()?;
        self.ref_name = Some(name.into());
        writeln!(self.out, "Lookup the '{name}' reference").ok();
        Ok(())
    }

    fn disambiguate_prefix(
        &mut self,
        prefix: gix::hash::Prefix,
        hint: Option<delegate::PrefixHint<'_>>,

View on GitHub (pinned to e73179060b)