{"record":{"id":"a8572a960fb24660","repo":"BoundaryML/baml","slug":"division-by-zero-at","errorCode":null,"errorMessage":"division by zero at {:?}","messagePattern":"division by zero at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2401,"sourceCode":"        BinaryOperator::Mul => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Int(a * b, meta.clone())\n            }\n            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Float(b, _)) => {\n                BamlValueWithMeta::Float(a * b, meta.clone())\n            }\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Float(b, _)) => {\n                BamlValueWithMeta::Float((a as f64) * b, meta.clone())\n            }\n            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Float(a * (b as f64), meta.clone())\n            }\n            _ => bail!(\"unsupported types for * operator at {:?}\", meta.0),\n        },\n        BinaryOperator::Div => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                if b == 0 {\n                    bail!(\"division by zero at {:?}\", meta.0);\n                }\n                BamlValueWithMeta::Float((a as f64) / (b as f64), meta.clone())\n            }\n            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Float(b, _)) => {\n                if b == 0.0 {\n                    bail!(\"division by zero at {:?}\", meta.0);\n                }\n                BamlValueWithMeta::Float(a / b, meta.clone())\n            }\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Float(b, _)) => {\n                if b == 0.0 {\n                    bail!(\"division by zero at {:?}\", meta.0);\n                }\n                BamlValueWithMeta::Float((a as f64) / b, meta.clone())\n            }\n            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Int(b, _)) => {\n                if b == 0 {\n                    bail!(\"division by zero at {:?}\", meta.0);","sourceCodeStart":2383,"sourceCodeEnd":2419,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2383-L2419","documentation":"The `/` division operator checks the divisor and bails when it is zero — for both integer division (b == 0) and float division (b == 0.0). The interpreter converts the error to a runtime failure at the expression's source position rather than producing infinity or NaN.","triggerScenarios":"Evaluating `a / b` where b is the integer 0 or float 0.0, including when b is a computed value or variable that happens to be zero (e.g. an empty-sum denominator, a count of zero items).","commonSituations":"Computing averages/ratios over empty collections (count = 0); user-supplied or LLM-supplied divisors that can be zero; percentages with total = 0.","solutions":["Check the divisor for zero before dividing and return a sentinel/default value for the zero case","Guarantee denominators come from validated, nonzero sources","For averages over possibly-empty lists, special-case the empty case","Catch the runtime error around evaluation and handle it"],"exampleFix":"// before\nlet avg = total / count;   // count can be 0\n// after\nlet avg = if (count == 0) { 0.0 } else { total / count };","handlingStrategy":"validation","validationCode":"if (divisor === 0 || divisor === 0.0) { throw new Error('guard: divisor is zero, skip division'); }","typeGuard":"function isNonZeroNumber(v) { return typeof v === 'number' && v !== 0; }","tryCatchPattern":"try { result = a / b; } catch (e) { if (String(e).includes('division by zero')) { result = defaultValue; } else { throw e; } }","preventionTips":["Always check divisors for zero before dividing","Special-case empty collections before computing averages","Validate user/LLM-supplied numeric inputs"],"tags":["runtime","arithmetic","division-by-zero","interpreter"],"backgroundTag":"invalid-argument-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}