spacedriveapp/spacedrive · error · anyhow::Error
Invalid number: {}
Error message
Invalid number: {} What it means
Thrown by parse_duration() when the first whitespace-separated token of a duration string cannot be parsed as i64. The parser expects '<integer> <unit>' (e.g. '30 minutes'), so any non-numeric first token (or a float like '1.5') fails at parts[0].parse::<i64>().
Source
Thrown at apps/cli/src/domains/sync/mod.rs:161
.map(|dt| dt.with_timezone(&Utc))
.or_else(|_| {
// Try common formats
DateTime::parse_from_str(time_str, "%Y-%m-%d %H:%M:%S")
.map(|dt| dt.with_timezone(&Utc))
})
.map_err(|_| anyhow::anyhow!("Invalid time format: {}", time_str))
}
}
fn parse_duration(duration_str: &str) -> Result<chrono::Duration> {
let parts: Vec<&str> = duration_str.split_whitespace().collect();
if parts.len() != 2 {
return Err(anyhow::anyhow!("Invalid duration format: {}", duration_str));
}
let value: i64 = parts[0]
.parse()
.map_err(|_| anyhow::anyhow!("Invalid number: {}", parts[0]))?;
let unit = parts[1].to_lowercase();
let seconds = match unit.as_str() {
"second" | "seconds" | "sec" | "s" => value,
"minute" | "minutes" | "min" | "m" => value * 60,
"hour" | "hours" | "h" => value * 3600,
"day" | "days" | "d" => value * 86400,
"week" | "weeks" | "w" => value * 604800,
_ => return Err(anyhow::anyhow!("Unknown time unit: {}", unit)),
};
Ok(chrono::Duration::seconds(seconds))
}
fn display_metrics(
snapshot: &sd_core::service::sync::metrics::snapshot::SyncMetricsSnapshot,
args: &SyncMetricsArgs,
) {View on GitHub (pinned to 6dfeccf211)
Solutions
- Use a whole number: --since '2 hours ago' instead of '1.5 hours ago'
- Pick a smaller unit to approximate fractions: '90 minutes ago'
- Avoid words as quantities; use absolute timestamps for precise values
Defensive patterns
Strategy: validation
Validate before calling
let first = duration_str.split_whitespace().next().unwrap_or("");
if first.parse::<i64>().is_err() {
eprintln!("Duration quantity must be a whole number, got '{}'", first);
return Ok(());
} Type guard
fn quantity_is_integer(d: &str) -> bool {
d.split_whitespace().next().map(|t| t.parse::<i64>().is_ok()).unwrap_or(false)
} Prevention
- Use whole numbers only - '1.5 hours' fails; write '90 minutes'
- Never use words as quantities ('half an hour')
- For fractional precision, switch to an absolute timestamp
When it happens
Trigger: --since 'half an hour ago' (first token 'half'), '--since "1.5 hours ago"' ('1.5' is not an i64), '--since "-2 days ago"' actually parses but note negatives pass through; '--since "several days ago"'.
Common situations: Natural-language quantities; decimal durations where fractional support was assumed; localized number formats like '1,5'.
Related errors
- Invalid duration format: {}
- Unknown time unit: {}
- Invalid time format: {}
- No paired devices found. Pair a device first with: sd networ
- Remote device {} is not online
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/392e1ff0881b700f.
Report an issue: GitHub.