{"record":{"id":"b0695c06e7ffdd4a","repo":"sxyazi/yazi","slug":"not-a-number","errorCode":null,"errorMessage":"not a number","messagePattern":"not a number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/data/macros.rs","lineNumber":72,"sourceCode":"\nmacro_rules! impl_into_number {\n\t($a:ty, $($b:ty),+ $(,)?) => {\n\t\timpl_into_number!(@impl ref   $a,  $a, $($b),+);\n\t\timpl_into_number!(@impl owned $a, &$a, $($b),+);\n\t};\n\t(@impl $kind:ident $t:ty, $a:ty, $($b:ty),+ $(,)?) => {\n\t\t$(\n\t\t\timpl TryFrom<$a> for $b {\n\t\t\t\ttype Error = anyhow::Error;\n\n\t\t\t\tfn try_from(value: $a) -> Result<Self, Self::Error> {\n\t\t\t\t\tpaste::paste! {\n\t\t\t\t\t\tOk(match ref_or_owned!($kind, value) {\n\t\t\t\t\t\t\t$t::Integer(i) if *i == *i as $b as i64 => *i as $b,\n\t\t\t\t\t\t\t$t::Number(n) if f64::from(*n) == f64::from(*n) as $b as f64 => f64::from(*n) as $b,\n\t\t\t\t\t\t\t$t::String(s) => s.parse()?,\n\t\t\t\t\t\t\t$t::Id(i) if i.get() == i.get() as $b as u64 => i.get() as $b,\n\t\t\t\t\t\t\t_ => anyhow::bail!(\"not a number\"),\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t)+\n\t};\n}\n","sourceCodeStart":54,"sourceCodeEnd":80,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-shared/src/data/macros.rs#L54-L80","documentation":"This error is raised by a generated Data-to-float conversion macro in yazi-shared. When converting a `Data` value into a float type (f32/f64), only Integer, Number, String, and Id variants are accepted — and Integer/Id only when losslessly representable; any other variant (Bool, Null, List, Map, etc.) hits the catch-all arm and bails with \"not a number\".","triggerScenarios":"Calling `Data::try_into::<f64>()` (or f32) on a Data value of variant Bool, Null, List, Map, or any other non-numeric type; also an Integer/Id value that loses precision on conversion falls through to this bail.","commonSituations":"Plugin arguments where a numeric option was omitted (Null) or mistakenly passed as a boolean or list; scripts driving yazi commands (e.g. scripts/moderate/main.js flows) supplying wrong-typed values for numeric parameters; config values intended as floats but provided as strings-of-other-shapes or nested tables.","solutions":["Inspect the Data value's variant before conversion and pass a genuine number or numeric string.","If the source may be absent, default it (e.g. 0.0) before calling the API.","For integer inputs that must stay exact, convert via the integer accessor instead of the float one.","Fix the producer side (Lua script/config) so the field is always a number type."],"exampleFix":"// before\nlet ratio: f64 = args.get(\"ratio\")?; // Data::Bool -> \"not a number\"\n// after\nlet ratio: f64 = match args.get::<Data>(\"ratio\")? {\n    Data::Number(n) => f64::from(*n),\n    Data::Integer(i) => *i as f64,\n    _ => 0.0, // or bail with a clear message\n};","handlingStrategy":"type-guard","validationCode":"fn as_float(d: &Data) -> Option<f64> {\n    match d {\n        Data::Integer(i) => Some(*i as f64),\n        Data::Number(n) => Some(f64::from(*n)),\n        Data::String(s) => s.parse().ok(),\n        Data::Id(i) => Some(i.get() as f64),\n        _ => None,\n    }\n}","typeGuard":"fn is_number_like(d: &Data) -> bool {\n    matches!(d, Data::Integer(_) | Data::Number(_) | Data::String(_) | Data::Id(_))\n}","tryCatchPattern":"let ratio: f64 = args.get(\"ratio\").and_then(|d| as_float(d)).unwrap_or(0.0);","preventionTips":["Default optional numeric args at the boundary before conversion.","Keep float fields as Number/Integer variants; never booleans or lists.","Round or normalize floats before passing them into typed conversions.","Add a unit test converting each expected arg variant."],"tags":["rust","type-conversion","data","yazi-shared"],"backgroundTag":"invalid-data-type-conversion","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}