{"record":{"id":"c35a2719a10dddfb","repo":"uutils/coreutils","slug":"getting-clock-resolution-not-implemented-unsuppor","errorCode":null,"errorMessage":"getting clock resolution not implemented (unsupported target)","messagePattern":"getting clock resolution not implemented \\(unsupported target\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/uu/date/src/date.rs","lineNumber":1178,"sourceCode":"                            \"date: warning: using midnight as starting time: 00:00:00\"\n                        );\n                    }\n                }\n            }\n            Ok(ParsedDateTime::InRange(result))\n        }\n        Ok(ParsedDateTime::Extended(date)) if allow_extended => Ok(ParsedDateTime::Extended(date)),\n        Ok(ParsedDateTime::Extended(_)) => Err((\n            input_str.into(),\n            parse_datetime::ParseDateTimeError::InvalidInput,\n        )),\n        Err(e) => Err((input_str.into(), e)),\n    }\n}\n\n#[cfg(not(any(unix, windows)))]\nfn get_clock_resolution() -> Timestamp {\n    unimplemented!(\"getting clock resolution not implemented (unsupported target)\");\n}\n\n#[cfg(all(unix, not(target_os = \"redox\")))]\n/// Returns the resolution of the system’s realtime clock.\n///\n/// # Panics\n///\n/// Panics if `clock_getres` fails. On a POSIX-compliant system this should not occur,\n/// as `CLOCK_REALTIME` is required to be supported.\n/// Failure would indicate a non-conforming or otherwise broken implementation.\nfn get_clock_resolution() -> Timestamp {\n    use rustix::time::{ClockId, clock_getres};\n\n    let timespec = clock_getres(ClockId::Realtime);\n\n    #[allow(clippy::unnecessary_cast, reason = \"needed for 32 bit target\")]\n    Timestamp::constant(timespec.tv_sec as _, timespec.tv_nsec as _)\n}","sourceCodeStart":1160,"sourceCodeEnd":1196,"githubUrl":"https://github.com/uutils/coreutils/blob/2c9a6666749473dc4bff876f5c4a9f25fde4c964/src/uu/date/src/date.rs#L1160-L1196","documentation":"This is a Rust `unimplemented!()` panic, not a recoverable error. uutils' `date` reimplementation selects `get_clock_resolution()` via `#[cfg]`: a rustix `clock_getres` version for unix (src/uu/date/src/date.rs:1189), a fixed 100ns constant for windows, and this panic stub for every other target. The function backs the `--resolution` flag (DateSource::Resolution, src/uu/date/src/date.rs:555-556), so on a target that is neither `unix` nor `windows` the process panics with exit code 101 as soon as that code path is compiled in and reached.","triggerScenarios":"Building the `date` binary (or the uu_date crate) for a target where neither `cfg(unix)` nor `cfg(windows)` holds - e.g. wasm32-unknown-unknown, wasm32-wasi, or a bare-metal/embedded target - and then invoking it with `--resolution` (parsed into DateSource::Resolution at src/uu/date/src/date.rs:555, which calls get_clock_resolution() unconditionally).","commonSituations":"Cross-compiling uutils/coreutils to wasm or an embedded OS for size/API experiments; a distro or vendor porting uutils to a niche OS inheriting the stub; contributors running the full flag surface in tests on an exotic host. On mainstream linux/macos/bsd/windows the stub is never compiled, so the panic only surprises non-standard target users.","solutions":["Run `cargo check --target <your-target>` and grep the build for which `get_clock_resolution` arm compiled; if your target is not unix/windows, either switch to a supported target or stop shipping the `--resolution` flag for it.","Patch the stub to fail gracefully like the macOS/Redox `set_system_datetime` branches do (return a UResult error instead of panicking) so callers see a normal CLI error instead of a panic.","Implement the function for your target using its native clock API (the unix arm at src/uu/date/src/date.rs:1189 shows the rustix `clock_getres` pattern; Windows shows the hardcoded-resolution fallback) and upstream it.","If you are embedding uu_date as a library, wrap the call in `std::panic::catch_unwind` and treat a panic payload containing \"getting clock resolution not implemented\" as 'unsupported'."],"exampleFix":"// before (src/uu/date/src/date.rs:1176-1179)\n#[cfg(not(any(unix, windows)))]\nfn get_clock_resolution() -> Timestamp {\n    unimplemented!(\"getting clock resolution not implemented (unsupported target)\");\n}\n\n// after - fail like the macOS/Redox set_system_datetime branches, not by panicking\n#[cfg(not(any(unix, windows)))]\nfn get_clock_resolution() -> UResult<Timestamp> {\n    Err(USimpleError::new(\n        1,\n        translate!(\"date-error-clock-resolution-not-supported\"),\n    ))\n}\n// callers: let resolution = get_clock_resolution()?;  (src/uu/date/src/date.rs:556)","handlingStrategy":"validation","validationCode":"// Decide before shipping/calling: this target has no get_clock_resolution impl\n#[cfg(any(unix, windows))]\nconst SUPPORTS_CLOCK_RESOLUTION: bool = true;\n#[cfg(not(any(unix, windows)))]\nconst SUPPORTS_CLOCK_RESOLUTION: bool = false;\n\nif !SUPPORTS_CLOCK_RESOLUTION {\n    eprintln!(\"date: --resolution is not supported on this target\");\n    std::process::exit(1);\n}\nlet resolution = get_clock_resolution(); // src/uu/date/src/date.rs:556","typeGuard":"fn has_clock_resolution_support() -> bool {\n    cfg!(any(unix, windows))\n}","tryCatchPattern":"use std::panic;\n\nlet attempt = panic::catch_unwind(get_clock_resolution);\nlet resolution = match attempt {\n    Ok(ts) => ts,\n    Err(payload) => {\n        let msg = payload\n            .downcast_ref::<String>()\n            .map(String::as_str)\n            .or_else(|| payload.downcast_ref::<&str>().copied())\n            .unwrap_or(\"panic\");\n        if msg.contains(\"not implemented\") {\n            // unsupported target: degrade, don't crash the caller\n            Timestamp::constant(0, 1)\n        } else {\n            std::panic::resume_unwind(payload);\n        }\n    }\n};","preventionTips":["Run `cargo check --target <triple>` for every deployment target and grep for cfg-gated `unimplemented!()`/`todo!()` arms before porting - the stub compiles silently.","Keep a runtime smoke test per shipped flag in CI on the actual target, not just the build host.","Hide flags like `--resolution` from the CLI (clap cfg gating) on targets lacking an implementation.","Prefer the repo's graceful-error pattern (return USimpleError like the macOS/Redox set_system_datetime branches) over unimplemented!() in any stub you add."],"tags":["rust","panic","cross-compilation","platform-support","date","clock-resolution"],"backgroundTag":"unsupported-platform-panic","analyzedSha":"2c9a6666749473dc4bff876f5c4a9f25fde4c964","analyzedAt":"2026-08-16T22:33:48.260Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}