{"record":{"id":"61a14039555a9adf","repo":"BoundaryML/baml","slug":"msg-at","errorCode":null,"errorMessage":"{msg} at {:?}","messagePattern":"\\{msg\\} at \\{:\\?\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":3013,"sourceCode":"                BamlValueWithMeta::Int(v, _) => *v as f64,\n                _ => bail!(\n                    \"to_fixed() method only available on floats and ints at {:?}\",\n                    meta.0\n                ),\n            };\n\n            if args.len() > 1 {\n                bail!(\"to_fixed() method takes at most 1 argument at {:?}\", meta.0);\n            }\n\n            let digits = match args.first() {\n                Some(BamlValueWithMeta::Int(v, _)) => *v,\n                Some(_) => bail!(\"to_fixed() digits argument must be an int at {:?}\", meta.0),\n                None => 0,\n            };\n\n            let formatted = baml_vm::native::number_to_fixed(value, digits)\n                .map_err(|msg| anyhow::anyhow!(\"{msg} at {:?}\", meta.0))?;\n            Ok(BamlValueWithMeta::String(formatted, meta.clone()))\n        }\n        _ => bail!(\n            \"unknown method '{}' at {:?}, should have been caught during typechecking\",\n            method_name,\n            meta.0\n        ),\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use std::path::PathBuf;\n\n    #[allow(unused_imports)]\n    use baml_types::ir_type::TypeIR;\n    use internal_baml_ast::parse_standalone_expression;\n    use internal_baml_diagnostics::{Diagnostics, SourceFile, Span};","sourceCodeStart":2995,"sourceCodeEnd":3031,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2995-L3031","documentation":"The call to baml_vm::native::number_to_fixed(value, digits) returned an Err carrying a message (e.g. out-of-range digit count), which the interpreter re-wraps with the source span via anyhow::anyhow!(\"{msg} at {:?}\"). This surfaces native numeric-formatting failures (typically digits outside the accepted range).","triggerScenarios":"Calling to_fixed with an out-of-range or otherwise rejected digits value that the native number_to_fixed implementation rejects (e.g. negative or excessively large digit counts, depending on the native bounds).","commonSituations":"Computing digits dynamically from data or LLM output so the value lands outside the accepted range at runtime; hardcoding an unusual precision like to_fixed(100).","solutions":["Clamp/validate the digits value before calling (e.g. ensure 0 <= digits <= 100)","Read the wrapped {msg} in the error to see the native constraint violated","Use a sane fixed precision such as 0–10 and guard dynamic values"],"exampleFix":"// before (unbounded dynamic digits)\nlet out = value.to_fixed(digits);\n// after\nlet d = if digits < 0 { 0 } else if digits > 100 { 100 } else { digits };\nlet out = value.to_fixed(d);","handlingStrategy":"validation","validationCode":"// clamp digits to a safe range before calling\nif (d < 0 || d > 100) { d = 2; }","typeGuard":null,"tryCatchPattern":"try { out = num.to_fixed(d); } catch (e) { log(e); out = num.to_fixed(2); }","preventionTips":["Clamp dynamic digit values to 0–100","Avoid extreme precisions","Log the wrapped native msg to learn exact bounds"],"tags":["runtime","numbers","formatting","baml"],"backgroundTag":"value-out-of-range","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}