sxyazi/yazi · error
not an integer
Error message
not an integer
What it means
Raised inside `float_to_i64` in yazi-shared/src/data/macros.rs when a floating-point value cannot be represented losslessly as an i64. It bails either when the value is non-finite (NaN/infinity) or has a fractional part, or when the `as i64` cast round-trips back to a different float (overflow beyond i64 range).
Solutions
- Validate the number before conversion: finite and `fract() == 0.0`.
- If fractional input is legitimate, round or truncate explicitly (`value.round() as i64`) instead of relying on TryFrom.
- Clamp/saturate extreme values before casting to avoid range overflow.
Example fix
// before
let n: i64 = Data::Number(3.5f64).try_into()?;
// after
let f = 3.5f64;
let n: i64 = if f.is_finite() && f.fract() != 0.0 { f.round() as i64 } else { f as i64 }; Defensive patterns
Strategy: validation
Validate before calling
fn is_lossless_i64(f: f64) -> bool {
f.is_finite() && f.fract() == 0.0 && f >= i64::MIN as f64 && f <= i64::MAX as f64
} Try / catch
match Data::Number(f).try_into() as Result<i64, _> {
Ok(n) => use_int(n),
Err(e) => log::warn!("{f} is not an integer: {e}"),
} Prevention
- Validate floats with is_finite() and fract() == 0.0 before integer conversion.
- Round explicitly at the source when fractional values are acceptable.
- Avoid floating-point arithmetic for counts/indices; keep integers as integers.
When it happens
Trigger: Converting `Data::Number(f32/f64)` via `impl_into_integer!` where the float is e.g. 3.5, NaN, or 1e300.
Common situations: Lua/plugin code passing a fractional number where an integer is required (e.g. an index or count), or calculations producing huge values that overflow i64.
Related errors
- argument not found
- Cache stamp does not match entry
- Cache stamp does not match target
- cannot convert to StrandBuf
- Cannot parse cache stamp
AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02).
Data as JSON: /api/errors/b35c926447651cf7.
Report an issue: GitHub.
Appendix: source
Thrown at yazi-shared/src/data/macros.rs:9
use anyhow::bail;
pub(crate) fn float_to_i64<T>(value: T) -> anyhow::Result<i64>
where
T: Into<f64>,
{
let value = value.into();
if !value.is_finite() || value.fract() != 0.0 {
bail!("not an integer");
}
let integer = value as i64;
if integer as f64 != value {
bail!("not an integer");
}
Ok(integer)
}
macro_rules! ref_or_owned {
(ref, $value:expr) => {
&$value
};
(owned, $value:expr) => {
$value
};
}View on GitHub (pinned to 5f901b886b)