astrid-runtime/astrid · error
byte value must be non-negative and finite
Error message
byte value must be non-negative and finite
What it means
After parsing the numeric part as f64, `parse_bytes` rejects negative, NaN, or infinite values because a byte quota must be a finite non-negative quantity. The cast to u64 is only safe because of this guard, so it fires before any conversion.
Source
Thrown at crates/astrid-cli/src/commands/quota.rs:347
}
// ── byte/duration parsers ──────────────────────────────────────────
/// Parse `"32"`, `"32B"`, `"32KB"`, `"32MB"`, `"32GB"`, `"32KiB"`,
/// `"32MiB"`, `"32GiB"`, `"32TB"`, `"32TiB"`. Lowercase accepted.
pub(crate) fn parse_bytes(s: &str) -> Result<u64> {
let trimmed = s.trim();
if trimmed.is_empty() {
anyhow::bail!("empty byte specifier");
}
// Strip optional `/s` (used by --ipc-rate).
let body = trimmed.strip_suffix("/s").unwrap_or(trimmed);
let (num_part, mult) = parse_numeric_suffix(body)?;
let num: f64 = num_part
.parse()
.with_context(|| format!("not a number: {num_part}"))?;
if num.is_sign_negative() || !num.is_finite() {
anyhow::bail!("byte value must be non-negative and finite");
}
#[expect(
clippy::cast_sign_loss,
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
reason = "guarded by sign and finite checks above"
)]
let bytes = (num * (mult as f64)) as u64;
Ok(bytes)
}
fn parse_numeric_suffix(body: &str) -> Result<(&str, u64)> {
// Find the index where the suffix (alphabetic or `i` for binary)
// begins. Consume digits and at most one `.`.
let split = body
.find(|c: char| !(c.is_ascii_digit() || c == '.'))
.unwrap_or(body.len());
let (num_part, suffix) = body.split_at(split);View on GitHub (pinned to affd8760f4)
Solutions
- Provide a finite non-negative value, e.g. `--storage 1GB`
- Fix the calculation producing the negative/NaN number in your script
- Use the documented 'unset/remove quota' mechanism instead of a sentinel like -1
Example fix
// before astrid quota set --storage -2GB // after astrid quota set --storage 2GB
Defensive patterns
Strategy: validation
Validate before calling
let n: f64 = /* parsed number */;
if !n.is_finite() || n.is_sign_negative() {
return Err("byte value must be finite and >= 0".into());
} Prevention
- Sanity-check computed quotas (assert > 0) before applying them
- Avoid sentinel negative values for 'unlimited'; use the tool's unset mechanism
- Beware float math that can yield NaN/inf in provisioning scripts
When it happens
Trigger: `--storage -5MB`, `--storage inf`, or `--storage nan` (the numeric portion parses as f64 but fails the sign/finite check).
Common situations: Sign mistakes in scripts (e.g. computing a quota via subtraction that goes negative), copy-pasted `Infinity`/`NaN` from JSON configs, or typos like `-1GB` intending 'unlimited'.
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
- empty byte specifier
- --retain-entries must be at least 1
- --retain-bytes must be greater than 0
- --var has an empty key (got {item:?})
- --var '{key}' was supplied more than once
AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09).
Data as JSON: /api/errors/aae379ced853db73.
Report an issue: GitHub.