{"record":{"id":"b9b484cf585c0c8a","repo":"BoundaryML/baml","slug":"plaindatetime-to-plain-date-expected-plaindatetime-instance","errorCode":null,"errorMessage":"PlainDateTime.to_plain_date: expected PlainDateTime instance","messagePattern":"PlainDateTime\\.to_plain_date: expected PlainDateTime instance","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_baml/time.rs","lineNumber":315,"sourceCode":"        let dt = civil_datetime(&plaindatetime._nanoseconds(), \"PlainDateTime.to_string\")?;\n        let mut out = String::new();\n        format_date_into(&mut out, dt.date());\n        out.push('T');\n        format_clock_into(\n            &mut out,\n            dt.hour(),\n            dt.minute(),\n            dt.second(),\n            dt.nanosecond(),\n        );\n        Ok(bex_str::BexStr::from(out))\n    }\n\n    fn to_plain_date(vm: &mut BexVm, plaindatetime: &Value) -> Result<Value, VmRustFnError> {\n        let civil = {\n            let instance = vm\n                .as_instance(plaindatetime)\n                .expect(\"PlainDateTime.to_plain_date: expected PlainDateTime instance\");\n            view::time::PlainDateTime { instance }._nanoseconds()\n        };\n        let days = i128::try_from(&*civil)\n            .ok()\n            .map(|n| n.div_euclid(NANOS_PER_DAY))\n            .and_then(|d| i64::try_from(d).ok())\n            .ok_or_else(|| {\n                invalid_argument(\n                    \"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","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_baml/time.rs#L297-L333","documentation":"Panic in PlainDateTime.to_plain_date: the receiver value is not a PlainDateTime instance, so reading its nanoseconds field fails. The method assumes its receiver is always a proper PlainDateTime instance.","triggerScenarios":"Calling to_plain_date with a receiver that is a PlainDate, PlainTime, or other non-PlainDateTime value.","commonSituations":"Confusing PlainDate with PlainDateTime when chaining conversions; retrieving dates from dynamic/untyped data; wrong-variable mistakes.","solutions":["Confirm the receiver was built with PlainDateTime constructors before calling to_plain_date.","If the value is a PlainDate, it already is a date — no conversion needed.","Type-check the value before the call."],"exampleFix":"// before\nlet d = plaindate.to_plain_date()\n// after\nlet d = plaindatetime.to_plain_date()  // receiver must be PlainDateTime","handlingStrategy":"type-guard","validationCode":"// before the call\nif (typeof value.className !== 'undefined' && value.className !== 'PlainDateTime') throw new Error('receiver must be a PlainDateTime');","typeGuard":"function isPlainDateTime(v) { return v != null && v.className === 'PlainDateTime'; }","tryCatchPattern":null,"preventionTips":["Chain conversions from correctly typed receivers.","Check the type of dynamically sourced date values before calling conversion methods."],"tags":["vm-panic","invariant","time","receiver-type"],"backgroundTag":"type-mismatch","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"}