{"record":{"id":"24c908c37fade0cb","repo":"can1357/oh-my-pi","slug":"invalid-zero-increment-value","errorCode":null,"errorMessage":"invalid Zero increment value: {}","messagePattern":"invalid Zero increment value: (.+?)","errorType":"error_code","errorClass":"SeqError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/seq.rs","lineNumber":440,"sourceCode":"use thiserror::Error;\nuse uucore::display::Quotable;\n\nuse super::numberparse::ParseNumberError;\n\n#[derive(Debug, Error)]\npub enum SeqError {\n\t/// An error parsing the input arguments.\n\t///\n\t/// The parameters are the [`String`] argument as read from the\n\t/// command line and the underlying parsing error itself.\n\t#[error(\"invalid {} argument: {}\", parse_error_type(.1), .0.quote())]\n\tParseError(String, ParseNumberError),\n\n\t/// The increment argument was zero, which is not allowed.\n\t///\n\t/// The parameter is the increment argument as a [`String`] as read\n\t/// from the command line.\n\t#[error(\"invalid Zero increment value: {}\", .0.quote())]\n\tZeroIncrement(String),\n\n\t/// No arguments were passed to this function, 1 or more is required\n\t#[error(\"missing operand\")]\n\tNoArguments,\n\n\t/// Both a format and equal width where passed to seq\n\t#[error(\"format string may not be specified when printing equal width strings\")]\n\tFormatAndEqualWidth,\n}\n\nfn parse_error_type(e: &ParseNumberError) -> &'static str {\n\tmatch e {\n\t\tParseNumberError::Float => \"floating point\",\n\t\tParseNumberError::Nan => \"'not-a-number'\",\n\t}\n}\n","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/seq.rs#L422-L458","documentation":"`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}'.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before: computed step can be zero\nlet step = end / divisions; // 0 when divisions > end\nseq(start, step, end)?;      // -> invalid Zero increment value: '0'\n\n// after: guard the step\nlet step = (end / divisions).max(1);\nseq(start, step, end)?;","handlingStrategy":"validation","validationCode":"fn validate_increment(step: &str) -> Result<f64, String> {\n    let v: f64 = step.trim().parse().map_err(|_| format!(\"not a number: {step:?}\"))?;\n    if v == 0.0 {\n        return Err(\"seq increment must be non-zero\".into());\n    }\n    Ok(v)\n}","typeGuard":"fn is_zero_increment(err: &SeqError) -> bool {\n    matches!(err, SeqError::ZeroIncrement(_))\n}","tryCatchPattern":"match seq_result {\n    Err(SeqError::ZeroIncrement(arg)) => {\n        eprintln!(\"seq: increment {arg} is zero; use a positive step to ascend or negative to descend\");\n    }\n    Err(e) => return Err(e.into()),\n    Ok(v) => Ok(v),\n}","preventionTips":["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."],"tags":["argument-parsing","validation","cli","rust"],"backgroundTag":"invalid-argument","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}