sharkdp/hexyl · error

block size argument must be positive

Error message

block size argument must be positive

What it means

PositiveI64::new rejects non-positive values; when the hex-parsed block size is zero or negative, b3sum reports 'block size argument must be positive'.

Solutions

  1. Pass a block size of at least 1 byte, e.g. --block-size 1
  2. Fix the shell variable/computation that yields 0
  3. Validate the value before invoking: `[ "$bs" -gt 0 ] || exit 1`

Example fix

// before
b3sum --block-size 0 file
// after
b3sum --block-size 4096 file
Defensive patterns

Strategy: validation

Validate before calling

[ "$bs" -gt 0 ] 2>/dev/null || { echo 'block size must be > 0' >&2; exit 1; }

Prevention

When it happens

Trigger: --block-size 0 or a hex expression evaluating to <= 0 (e.g. --block-size 0x0).

Common situations: Script variables defaulting to 0; computing sizes in shell arithmetic that yields 0; copy-pasting '0' as block size.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at src/main.rs:305

            if filename.as_os_str() == "-" {
                Input::Stdin(stdin.lock())
            } else {
                if filename.is_dir() {
                    bail!("'{}' is a directory.", filename.to_string_lossy());
                }
                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

View on GitHub (pinned to 6ecc29b9c8)