sharkdp/hexyl · error

can not use 'block(s)' as a unit to specify block size

Error message

can not use 'block(s)' as a unit to specify block size

What it means

The 'block' unit refers to the block size itself, so using it to *define* the block size would be circular. b3sum explicitly rejects --block-size values with the block unit.

Solutions

  1. Use a concrete byte unit for --block-size, e.g. --block-size 4096, 4k, 1MiB
  2. Remove the 'blocks' suffix from the value
  3. Use blocks units only in --skip/--length, not --block-size

Example fix

// before
b3sum --block-size 4blocks file
// after
b3sum --block-size 4k file
Defensive patterns

Strategy: validation

Validate before calling

case "$bs" in *block*|*blocks*) echo 'blocks unit not allowed for --block-size' >&2; exit 1;; esac

Prevention

When it happens

Trigger: --block-size 2blocks, --block-size 1block, or any --block-size value whose parsed Unit is Unit::Block (including custom block sizes).

Common situations: Confusing --skip/--length style offsets (which may use block units) with the block-size definition; copying an offset expression into --block-size.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at src/main.rs:311

                let file = File::open(filename)?;

                Input::File(file)
            }
        }
        None => Input::Stdin(stdin.lock()),
    };

    if let Some(hex_number) = try_parse_as_hex_number(&opt.block_size) {
        return hex_number
            .map_err(|e| anyhow!(e))
            .and_then(|x| {
                PositiveI64::new(x).ok_or_else(|| anyhow!("block size argument must be positive"))
            })
            .map(|_| ());
    }
    let (num, unit) = extract_num_and_unit_from(&opt.block_size)?;
    if let Unit::Block { custom_size: _ } = unit {
        return Err(anyhow!(
            "can not use 'block(s)' as a unit to specify block size"
        ));
    };
    let block_size = num
        .checked_mul(unit.get_multiplier())
        .ok_or_else(|| anyhow!(ByteOffsetParseError::UnitMultiplicationOverflow))
        .and_then(|x| {
            PositiveI64::new(x).ok_or_else(|| anyhow!("block size argument must be positive"))
        })?;

    let skip_arg = opt
        .skip
        .as_ref()
        .map(|s| {
            parse_byte_offset(s, block_size).context(anyhow!(
                "failed to parse `--skip` arg {:?} as byte count",
                s
            ))

View on GitHub (pinned to 6ecc29b9c8)