can1357/oh-my-pi · error · SeqError
invalid Zero increment value: {}
Error message
invalid Zero increment value: {} What it means
`SeqError::ZeroIncrement` from the seq builtin: an explicit increment operand of zero was supplied. GNU seq semantics forbid a zero increment because the sequence would either never terminate or never move from the start value, so the library rejects it upfront with 'invalid Zero increment value: {arg}'.
Source
Thrown at crates/pi-builtins/src/seq.rs:440
use thiserror::Error;
use uucore::display::Quotable;
use super::numberparse::ParseNumberError;
#[derive(Debug, Error)]
pub enum SeqError {
/// An error parsing the input arguments.
///
/// The parameters are the [`String`] argument as read from the
/// command line and the underlying parsing error itself.
#[error("invalid {} argument: {}", parse_error_type(.1), .0.quote())]
ParseError(String, ParseNumberError),
/// The increment argument was zero, which is not allowed.
///
/// The parameter is the increment argument as a [`String`] as read
/// from the command line.
#[error("invalid Zero increment value: {}", .0.quote())]
ZeroIncrement(String),
/// No arguments were passed to this function, 1 or more is required
#[error("missing operand")]
NoArguments,
/// Both a format and equal width where passed to seq
#[error("format string may not be specified when printing equal width strings")]
FormatAndEqualWidth,
}
fn parse_error_type(e: &ParseNumberError) -> &'static str {
match e {
ParseNumberError::Float => "floating point",
ParseNumberError::Nan => "'not-a-number'",
}
}
View on GitHub (pinned to 9690622007)
Solutions
- Replace the zero increment with a positive value for an ascending sequence or a negative value for a descending one (e.g. `seq 1 1 10`).
- If the step is computed, guard it: clamp to a minimum magnitude or reject zero before calling seq.
- If you only wanted start..end, use the two-operand form `seq 1 10` which implies increment 1.
- In calling code, validate the parsed increment (`step != 0`) before invoking the seq API and return a domain-specific error.
- For descending sequences, remember the increment must be negative (`seq 10 -1 1`); a zero is never valid.
Example fix
// before: computed step can be zero let step = end / divisions; // 0 when divisions > end seq(start, step, end)?; // -> invalid Zero increment value: '0' // after: guard the step let step = (end / divisions).max(1); seq(start, step, end)?;
Defensive patterns
Strategy: validation
Validate before calling
fn validate_increment(step: &str) -> Result<f64, String> {
let v: f64 = step.trim().parse().map_err(|_| format!("not a number: {step:?}"))?;
if v == 0.0 {
return Err("seq increment must be non-zero".into());
}
Ok(v)
} Type guard
fn is_zero_increment(err: &SeqError) -> bool {
matches!(err, SeqError::ZeroIncrement(_))
} Try / catch
match seq_result {
Err(SeqError::ZeroIncrement(arg)) => {
eprintln!("seq: increment {arg} is zero; use a positive step to ascend or negative to descend");
}
Err(e) => return Err(e.into()),
Ok(v) => Ok(v),
} Prevention
- Guard any computed step size against degenerating to zero before calling seq.
- Use the two-operand form `seq START END` when you don't need a custom increment.
- For descending sequences, remember the increment must be negative, never zero.
- Validate user-supplied stride configuration at load time (reject 0) rather than at seq call time.
When it happens
Trigger: Invoking the three-operand form with a zero middle argument: `seq 1 0 10`, `seq 5 0.0 1`, or computing the increment dynamically (`seq $start $step $end`) where the step expression evaluates to 0 — including `seq 1 $((2-2)) 5` in shells.
Common situations: Step sizes computed from configuration or arithmetic that degenerate to zero (empty loop-stride config, division result of 0); scripts that pass user-provided stride without validation; typos like `seq 1 00 10`; translating a Python `range`-style call incorrectly (range(1,10) misread as seq 1 10 needing a middle term).
Related errors
- invalid {} argument: {}
- --agents must be a positive integer
- --trusted-extension requires a non-empty, non-flag value
- Invalid --state '${raw}'. Valid values: ${GALLERY_STATE_TOKE
- Invalid credential id: ${value}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/24c908c37fade0cb.
Report an issue: GitHub.