{"record":{"id":"2b70452507f6346d","repo":"BoundaryML/baml","slug":"time-of-day-fits-in-i64","errorCode":null,"errorMessage":"time-of-day fits in i64","messagePattern":"time-of-day fits in i64","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_baml/time.rs","lineNumber":342,"sourceCode":"                    \"PlainDateTime.to_plain_date: value is outside the supported year range\"\n                        .to_string(),\n                )\n            })?;\n        Ok(copy::time::PlainDate { _days: days }.to_value(vm))\n    }\n\n    fn to_plain_time(vm: &mut BexVm, plaindatetime: &Value) -> Value {\n        let civil = {\n            let instance = vm\n                .as_instance(plaindatetime)\n                .expect(\"PlainDateTime.to_plain_time: expected PlainDateTime instance\");\n            view::time::PlainDateTime { instance }._nanoseconds()\n        };\n        // Euclidean modulo one day is exact regardless of the bigint's\n        // magnitude or sign, and the result always fits in an i64.\n        let day = num_bigint::BigInt::from(NANOS_PER_DAY);\n        let time_ns = ((&*civil % &day) + &day) % &day;\n        let time_ns = i64::try_from(time_ns).expect(\"time-of-day fits in i64\");\n        copy::time::PlainTime {\n            _nanoseconds: time_ns,\n        }\n        .to_value(vm)\n    }\n\n    fn year(plaindatetime: &view::time::PlainDateTime<'_>) -> Result<i64, VmRustFnError> {\n        Ok(i64::from(\n            civil_datetime(&plaindatetime._nanoseconds(), \"PlainDateTime.year\")?.year(),\n        ))\n    }\n\n    fn month(plaindatetime: &view::time::PlainDateTime<'_>) -> Result<i64, VmRustFnError> {\n        Ok(i64::from(u8::from(\n            civil_datetime(&plaindatetime._nanoseconds(), \"PlainDateTime.month\")?.month(),\n        )))\n    }\n","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_baml/time.rs#L324-L360","documentation":"Internal invariant panic in PlainDateTime.to_plain_time: after Euclidean-modulo reduction to one day (NANOS_PER_DAY), the nanosecond-of-day value must mathematically fit in an i64 (0..86,399,999,999,999). i64::try_from().expect() can only fail if the modulo logic is broken or NANOS_PER_DAY is corrupted.","triggerScenarios":"Essentially unreachable from user code; would require a corrupted PlainDateTime nanosecond bigint or a bug in the reduction arithmetic.","commonSituations":"Hit only during development of the VM itself, or if a bug allows out-of-spec bigint states into PlainDateTime internals.","solutions":["Report to maintainers with the exact datetime value that triggered it.","Verify the PlainDateTime instance was not constructed via internal/private field access.","Check for VM/version mismatch; upgrade to the latest bex_vm build."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Validate the instance was produced by the library before calling to_plain_time()\nfn is_valid_plain_datetime(v: &Value, vm: &BexVm) -> bool {\n    vm.as_instance(v).map(|i| i.class() == \"PlainDateTime\").unwrap_or(false)\n}","typeGuard":"fn as_plain_datetime<'a>(vm: &'a BexVm, v: &Value) -> Option<InstanceRef<'a>> {\n    vm.as_instance(v).ok().filter(|i| i.class() == \"PlainDateTime\")\n}","tryCatchPattern":"// Rust caller: use catch_unwind around VM invocations to convert panics into errors\nstd::panic::catch_unwind(|| vm_call_to_plain_time(...)).unwrap_or_else(|_| Err(VmError::Internal))","preventionTips":["Use only library-produced PlainDateTime values.","Keep the VM updated; this panic signals a VM bug, not input error.","Report reproductions to maintainers with the exact value."],"tags":["rust","panic","internal-invariant","bigint"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}