{"record":{"id":"d54e53b1f952f224","repo":"a-b-street/abstreet","slug":"mod","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"widgetry/src/tools/mod.rs","lineNumber":121,"sourceCode":"        {\n            error!(\"Copying to clipboard broke: {}\", err);\n        }\n    }\n\n    #[cfg(target_arch = \"wasm32\")]\n    {\n        let _ = x;\n    }\n}\n\npub fn get_clipboard() -> Result<String> {\n    #[cfg(not(target_arch = \"wasm32\"))]\n    {\n        use clipboard::{ClipboardContext, ClipboardProvider};\n        // TODO The clipboard crate uses old nightly Errors. Converting to anyhow is weird.\n        let mut ctx: ClipboardContext = match ClipboardProvider::new() {\n            Ok(ctx) => ctx,\n            Err(err) => bail!(\"{}\", err),\n        };\n        let contents = match ctx.get_contents() {\n            Ok(contents) => contents,\n            Err(err) => bail!(\"{}\", err),\n        };\n        Ok(contents)\n    }\n\n    #[cfg(target_arch = \"wasm32\")]\n    {\n        bail!(\"Unsupported on web\");\n    }\n}\n","sourceCodeStart":103,"sourceCodeEnd":135,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/widgetry/src/tools/mod.rs#L103-L135","documentation":"get_clipboard on native (non-wasm) platforms wraps any failure from creating the clipboard-core ClipboardContext into an anyhow error whose message is just the underlying error's Display output. The library re-raises the clipboard crate's error verbatim because the clipboard crate uses an old nightly-style Error trait that does not convert cleanly to anyhow::Error. Seeing \"{}\"-style opaque output means the clipboard backend itself failed to initialize.","triggerScenarios":"Calling widgetry::tools::get_clipboard() on a native build when ClipboardContext::new() fails, e.g. no X11/Wayland clipboard server available or the clipboard backend cannot connect to the display.","commonSituations":"Running a headless Linux server or CI container without X11/Wayland; running under SSH without X forwarding; window-manager session not started so no clipboard daemon exists.","solutions":["Run the app inside a graphical session (X11 or Wayland) so a clipboard service exists","Enable X forwarding (ssh -X/-Y) or use xauth/xvfb with a clipboard manager when remote","Check that the platform-specific clipboard dependency (x11-clipboard/wayland) is built and its runtime libs are installed","Rephrase: the message is just err.to_string(); match on its text to identify the underlying backend failure"],"exampleFix":"// before\nlet text = get_clipboard().unwrap();\n// after\nlet text = match get_clipboard() {\n    Ok(t) => t,\n    Err(e) => { eprintln!(\"clipboard unavailable: {e}\"); String::new() }\n};","handlingStrategy":"fallback","validationCode":"let clipboard_available = !cfg!(target_arch = \"wasm32\") && std::env::var(\"DISPLAY\").map(|d| !d.is_empty()).unwrap_or(false) || std::env::var(\"WAYLAND_DISPLAY\").is_ok();","typeGuard":"fn clipboard_likely_available() -> bool {\n    std::env::var(\"WAYLAND_DISPLAY\").is_ok() || std::env::var(\"DISPLAY\").map(|d| !d.is_empty()).unwrap_or(false)\n}","tryCatchPattern":"let text = match get_clipboard() {\n    Ok(t) => t,\n    Err(e) => { log::warn!(\"clipboard init failed: {e}\"); String::new() }\n};","preventionTips":["Treat clipboard access as best-effort; never unwrap the result","Check for DISPLAY/WAYLAND_DISPLAY before calling on Linux","Provide a manual paste input field as a fallback","Avoid calling clipboard APIs in headless/CI environments"],"tags":["clipboard","native","wasm","anyhow"],"backgroundTag":"unsupported-operation","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}