{"record":{"id":"4778b980263f6ce3","repo":"uutils/coreutils","slug":"setting-date-not-implemented-unsupported-target","errorCode":null,"errorMessage":"setting date not implemented (unsupported target)","messagePattern":"setting date not implemented \\(unsupported target\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/uu/date/src/date.rs","lineNumber":1217,"sourceCode":"fn get_clock_resolution() -> Timestamp {\n    // Redox OS does not support the posix clock_getres function, however\n    // internally it uses a resolution of 1ns to represent timestamps.\n    // https://gitlab.redox-os.org/redox-os/kernel/-/blob/master/src/time.rs\n    Timestamp::constant(0, 1)\n}\n\n#[cfg(windows)]\nfn get_clock_resolution() -> Timestamp {\n    // Windows does not expose a system call for getting the resolution of the\n    // clock, however the FILETIME struct returned by GetSystemTimeAsFileTime,\n    // and GetSystemTimePreciseAsFileTime has a resolution of 100ns.\n    // https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime\n    Timestamp::constant(0, 100)\n}\n\n#[cfg(not(any(unix, windows)))]\nfn set_system_datetime(_date: Zoned) -> UResult<()> {\n    unimplemented!(\"setting date not implemented (unsupported target)\");\n}\n\n/// Convert a parsed date for the system clock.\nfn convert_for_set(date: Zoned, utc: bool) -> Zoned {\n    if utc {\n        date.timestamp().to_zoned(TimeZone::UTC)\n    } else {\n        date\n    }\n}\n\n#[cfg(target_os = \"macos\")]\nfn set_system_datetime(_date: Zoned) -> UResult<()> {\n    Err(USimpleError::new(\n        1,\n        translate!(\"date-error-setting-date-not-supported-macos\"),\n    ))\n}","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/uutils/coreutils/blob/2c9a6666749473dc4bff876f5c4a9f25fde4c964/src/uu/date/src/date.rs#L1199-L1235","documentation":"A Rust `unimplemented!()` panic compiled into uu_date only when the target is neither `unix` nor `windows`. `set_system_datetime()` is what `date --set=...` / `date -s ...` calls (src/uu/date/src/date.rs:389-390); supported targets use `clock_settime` (unix, src/uu/date/src/date.rs:1251) or `SetSystemTime` (windows, src/uu/date/src/date.rs:1270), while macOS and Redox deliberately return a graceful `USimpleError` (src/uu/date/src/date.rs:1230,1238). The catch-all stub predates that graceful pattern, so on exotic targets `--set` aborts the process with a panic instead of printing an error.","triggerScenarios":"Compile the `date` binary for any target without `cfg(unix)`/`cfg(windows)` (wasm, bare-metal, custom OS ports) and run it with `--set=DATE` or `-s DATE`; the Some(date) branch at src/uu/date/src/date.rs:389 calls this stub directly and panics with exit code 101.","commonSituations":"Vendors cross-compiling uutils/coreutils to wasm or embedded/niche OSes; container/sandbox images built for unusual triples that still run config scripts; test harnesses that exercise every flag of the binary on a non-standard host. Linux/macOS/BSD/Windows users never hit it because a real implementation or graceful error is compiled instead.","solutions":["If you do not need `--set` on that target, exclude or ignore the flag (don't run `date -s`) - every other date feature works.","Patch the stub to mirror the macOS/Redox pattern and return `USimpleError::new(1, translate!(\"date-error-setting-date-not-supported-...\"))` instead of `unimplemented!()`, then upstream it (the repo's rule: a PR needs a test in tests/by-util/test_date.rs).","Implement `set_system_datetime` for your target with its native 'set system clock' syscall, following the rustix `clock_settime` shape at src/uu/date/src/date.rs:1251.","As a library consumer, call `std::panic::catch_unwind` around any uu_date entry point that may reach `--set`, and check the payload string."],"exampleFix":"// before (src/uu/date/src/date.rs:1215-1218)\n#[cfg(not(any(unix, windows)))]\nfn set_system_datetime(_date: Zoned) -> UResult<()> {\n    unimplemented!(\"setting date not implemented (unsupported target)\");\n}\n\n// after - same graceful-error pattern the macOS and Redox arms already use\n#[cfg(not(any(unix, windows)))]\nfn set_system_datetime(_date: Zoned) -> UResult<()> {\n    Err(USimpleError::new(\n        1,\n        translate!(\"date-error-setting-date-not-supported\"),\n    ))\n}","handlingStrategy":"validation","validationCode":"// Gate the --set code path before it reaches the stub (src/uu/date/src/date.rs:389)\n#[cfg(not(any(unix, windows)))]\nfn can_set_system_datetime() -> bool {\n    false // only the unimplemented!() stub is compiled on this target\n}\n#[cfg(any(unix, windows))]\nfn can_set_system_datetime() -> bool {\n    true\n}\n\nif settings.set_to.is_some() && !can_set_system_datetime() {\n    return Err(USimpleError::new(1, \"date: setting the date is not supported on this target\"));\n}","typeGuard":"fn supports_setting_date() -> bool {\n    cfg!(any(unix, windows))\n}","tryCatchPattern":"use std::panic;\n\n// set_system_datetime returns UResult, but the unsupported-target stub panics\nlet outcome = panic::catch_unwind(|| set_system_datetime(convert_for_set(date, utc)));\nmatch outcome {\n    Ok(result) => result?,\n    Err(payload) => {\n        let msg = payload.downcast_ref::<String>().map(String::as_str);\n        if msg.is_some_and(|m| m.contains(\"not implemented\")) {\n            eprintln!(\"date: --set unsupported on this target\");\n            std::process::exit(1);\n        }\n        std::panic::resume_unwind(payload);\n    }\n}","preventionTips":["Never run `date --set`/`-s` on binaries built for non-unix non-windows targets; the stub is compiled in by cfg, not detected at runtime.","Audit cfg arms with unimplemented!() when adding a new target triple, and convert them to USimpleError errors (the macOS branch at date.rs:1230 is the model).","Exclude the --set option at the clap layer via cfg on unsupported targets so users cannot reach the panic.","Smoke-test every privileged flag after cross-compiling; stubs pass cargo build and only fail at runtime."],"tags":["rust","panic","cross-compilation","platform-support","date","system-clock","set-time"],"backgroundTag":"unsupported-platform-panic","analyzedSha":"2c9a6666749473dc4bff876f5c4a9f25fde4c964","analyzedAt":"2026-08-16T22:33:48.260Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}