{"record":{"id":"95dcc796948fe52b","repo":"BoundaryML/baml","slug":"system-clock-is-set-before-the-unix-epoch","errorCode":null,"errorMessage":"system clock is set before the UNIX epoch","messagePattern":"system clock is set before the UNIX epoch","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bridge_wasm/src/wasm_time.rs","lineNumber":111,"sourceCode":"        .map_err(|e| other(\"Temporal.ZonedDateTime is not a constructor\", &e))?;\n    let args = Array::of2(epoch_ns, &JsValue::from_str(timezone));\n    Ok(Reflect::construct(&ctor, &args)\n        .ok()\n        .and_then(|v| v.dyn_into::<Object>().ok()))\n}\n\nimpl io::IoClassTimeInstant for WasmTime {\n    fn now(\n        &self,\n        _heap: &Arc<BexHeap>,\n        _call_id: CallId,\n        _ctx: &SysOpContext,\n    ) -> SysOpOutput<owned::time::Instant> {\n        // Wall-clock time as nanoseconds since the UNIX epoch. Per the\n        // `Instant.now()` contract, an unavailable/pre-epoch clock panics.\n        let nanos = web_time::SystemTime::now()\n            .duration_since(web_time::UNIX_EPOCH)\n            .expect(\"system clock is set before the UNIX epoch\")\n            .as_nanos();\n        SysOpOutput::ok(owned::time::Instant {\n            _nanoseconds: Arc::new(num_bigint::BigInt::from(nanos)),\n        })\n    }\n}\n\nimpl io::IoNamespaceTime for WasmTime {\n    fn system_timezone(\n        &self,\n        _heap: &Arc<BexHeap>,\n        _call_id: CallId,\n        _ctx: &SysOpContext,\n    ) -> SysOpOutput<String> {\n        // Temporal.Now.timeZoneId()\n        let result: Result<String, VmRustFnError> = (|| {\n            let temporal = temporal()?;\n            let now = Reflect::get(&temporal, &\"Now\".into())","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bridge_wasm/src/wasm_time.rs#L93-L129","documentation":"The WASM sys-op now() returns wall-clock nanoseconds since the UNIX epoch per the Instant.now() contract. If web_time::SystemTime::now() reports a time before the epoch, duration_since returns Err and the code panics with 'system clock is set before the UNIX epoch'. The library intentionally panics because a pre-epoch clock cannot be represented as a valid Instant.","triggerScenarios":"Calling Instant.now() (the time sys-op) while the host/browser reports a system clock earlier than 1970-01-01T00:00:00Z.","commonSituations":"VMs or embedded devices with unset RTC clocks booting at epoch 0, misconfigured NTP/timezones resetting system time, or test environments faking Date/SystemTime with negative offsets.","solutions":["Fix the host system clock (sync via NTP) so it reports a post-epoch time","In tests, mock time with values after the UNIX epoch","Wrap time sys-op calls to detect obviously invalid clocks before invoking now()","Report/raise an environment error instead of calling now() when the clock is known bad"],"exampleFix":"// before\nconst t = sys.now(); // panics if clock < epoch\n// after\nif (Date.now() < 0) throw new Error('system clock before UNIX epoch');\nconst t = sys.now();","handlingStrategy":"validation","validationCode":"if (Date.now() <= 0) throw new Error('Host system clock is before the UNIX epoch; fix system time');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sync host clocks with NTP, especially in VMs/containers","Never mock system time with pre-epoch values in tests","Check clock sanity at app startup before time-dependent calls","Avoid calling Instant.now() on environments known to have unset RTCs"],"tags":["wasm","time","clock"],"backgroundTag":"invalid-env-var-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"}