sharkdp/hexyl · error

failed to parse `--length` arg

Error message

failed to parse `--length` arg {:?} as byte count

What it means

The --length argument must parse as a byte count via parse_byte_count; on failure the error is wrapped with context 'failed to parse `--length` arg ... as byte count'.

Solutions

  1. Pass an integer byte count or valid unit expression, e.g. --length 1024 or --length 4k
  2. Strip whitespace/quotes from shell variables used for --length
  3. Check the underlying parse error printed beneath the context message for the offending character

Example fix

// before
b3sum --length 1.5k file
// after
b3sum --length 1536 file
Defensive patterns

Strategy: validation

Validate before calling

[[ "$len" =~ ^[0-9]+(k|KiB|M|MiB|G|GiB)?$ ]] || { echo "bad --length: $len" >&2; exit 1; }

Prevention

When it happens

Trigger: --length with malformed values like --length 5MBx, --length 1.5, --length '' , or an unsupported unit suffix.

Common situations: Typing decimal fractions where only integers are accepted; wrong unit spelling; shell variables containing whitespace or units from other tools (e.g. '5M' vs '5MiB' expectations).

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of sharkdp/hexyl@6ecc29b9c8 (2026-09-09). Data as JSON: /api/errors/8f52da4004c2056e. Report an issue: GitHub.

Appendix: source

Thrown at src/main.rs:360

            .map_err(|_| {
                anyhow!(
                    "Failed to jump to the desired input position. \
                     This could be caused by a negative offset that is too large or by \
                     an input that is not seek-able (e.g. if the input comes from a pipe)."
                )
            })?
    } else {
        0
    };

    let parse_byte_count = |s| -> Result<u64> {
        Ok(parse_byte_offset(s, block_size)?
            .assume_forward_offset_from_start()?
            .into())
    };

    let mut reader = if let Some(ref length) = opt.length {
        let length = parse_byte_count(length).context(anyhow!(
            "failed to parse `--length` arg {:?} as byte count",
            length
        ))?;
        Box::new(reader.take(length))
    } else {
        reader.into_inner()
    };

    let no_color = std::env::var_os("NO_COLOR").is_some();
    let show_color = match opt.color {
        ColorWhen::Never => false,
        ColorWhen::Always => !no_color,
        ColorWhen::Force => true,
        ColorWhen::Auto => {
            if no_color {
                false
            } else {
                supports_color::on(supports_color::Stream::Stdout)

View on GitHub (pinned to 6ecc29b9c8)