{"record":{"id":"7498452205d8f4e9","repo":"BoundaryML/baml","slug":"offset-fits-in-baml-int-toml","errorCode":null,"errorMessage":"offset fits in BAML int","messagePattern":"offset fits in BAML int","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_baml/toml.rs","lineNumber":132,"sourceCode":"    let time_ns = datetime.time.map(|t| {\n        i64::from(t.hour) * NANOS_PER_HOUR\n            + i64::from(t.minute) * NANOS_PER_MINUTE\n            + i64::from(t.second) * NANOS_PER_SECOND\n            + i64::from(t.nanosecond)\n    });\n\n    match (days, time_ns, datetime.offset) {\n        // Offset Date-Time → ZonedDateTime with a fixed offset.\n        (Some(days), Some(time_ns), Some(offset)) => {\n            let offset_ns = match offset {\n                ::toml::value::Offset::Z => 0,\n                ::toml::value::Offset::Custom { minutes } => i64::from(minutes) * NANOS_PER_MINUTE,\n            };\n            let civil = i128::from(days) * NANOS_PER_DAY + i128::from(time_ns);\n            let epoch = civil - i128::from(offset_ns);\n            let zoned = super::copy::time::ZonedDateTime {\n                _nanoseconds: Arc::new(num_bigint::BigInt::from(epoch)),\n                _offset_ns: Value::try_int(offset_ns).expect(\"offset fits in BAML int\"),\n                _iana: Value::NULL,\n            };\n            Ok(zoned.to_value(vm))\n        }\n        // Local Date-Time → PlainDateTime.\n        (Some(days), Some(time_ns), None) => {\n            let civil = i128::from(days) * NANOS_PER_DAY + i128::from(time_ns);\n            let plain = super::copy::time::PlainDateTime {\n                _nanoseconds: Arc::new(num_bigint::BigInt::from(civil)),\n            };\n            Ok(plain.to_value(vm))\n        }\n        // Local Date → PlainDate.\n        (Some(days), None, None) => Ok(super::copy::time::PlainDate { _days: days }.to_value(vm)),\n        // Local Time → PlainTime.\n        (None, Some(time_ns), None) => Ok(super::copy::time::PlainTime {\n            _nanoseconds: time_ns,\n        }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_baml/toml.rs#L114-L150","documentation":"Internal invariant panic when converting a TOML datetime (with a custom numeric offset) into a ZonedDateTime. The offset in minutes comes from the TOML document and is converted to nanoseconds, then wrapped in Value::try_int().expect(); a BAML int is i64-backed, so only an offset outside i64 range can trip it.","triggerScenarios":"A TOML document containing an offset datetime whose custom offset minutes yield a nanosecond value beyond i64 range (e.g. astronomically large minutes field in a hand-written/hacked TOML file).","commonSituations":"Ingesting untrusted or machine-generated TOML config with corrupted datetime offsets; hand-edited config files.","solutions":["Validate TOML datetime offsets before conversion (within ±24h).","Sanitize/repair the TOML source file.","Wrap conversion with a catch/abort boundary if ingesting untrusted TOML.","Report to maintainers if a valid RFC 3339 offset triggers it (should be impossible)."],"exampleFix":"// before (bad TOML)\nts = 2024-01-01T00:00:00+999999999999:00\n// after\nts = 2024-01-01T00:00:00+05:30","handlingStrategy":"validation","validationCode":"// Validate TOML datetime offsets before conversion\nfn toml_offset_in_range(minutes: i64) -> bool { minutes.abs() <= 24 * 60 }","typeGuard":null,"tryCatchPattern":"// Wrap TOML->Value conversion for untrusted files\nstd::panic::catch_unwind(|| toml_to_zoned(doc)).unwrap_or_else(|_| Err(ConfigError::BadDatetimeOffset))","preventionTips":["Validate offsets in TOML datetime values (within ±24h) at ingestion.","Treat machine-generated TOML as untrusted and sanitize it.","Reject or repair config files with absurd datetime offsets before conversion."],"tags":["rust","panic","toml","timezone","overflow"],"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"}