{"record":{"id":"8923ec58ee151a04","repo":"xai-org/grok-build","slug":"no-home-directory-resolves-set-grok-copy-file-to","errorCode":null,"errorMessage":"no home directory resolves; set GROK_COPY_FILE to enable the copy backup file","messagePattern":"no home directory resolves; set GROK_COPY_FILE to enable the copy backup file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/codegen/xai-grok-pager-render/src/clipboard/mod.rs","lineNumber":603,"sourceCode":"        file.set_permissions(std::fs::Permissions::from_mode(0o600))?;\n        file.write_all(text.as_bytes())\n    }\n    #[cfg(not(unix))]\n    std::fs::write(path, text)\n}\n\n/// Write to the default fallback path ([`default_copy_fallback_path`]).\n///\n/// Errors with `NotFound` when no fallback path resolves (no home and no\n/// `GROK_COPY_FILE`) — the backup file is skipped rather than written to a\n/// predictable temp location.\n///\n/// On Unix a missing parent directory is created `0700` (a custom\n/// `GROK_COPY_FILE` may point at a not-yet-created private directory;\n/// `~/.grok` normally already exists).\npub fn write_copy_fallback(text: &str) -> std::io::Result<std::path::PathBuf> {\n    let Some(path) = default_copy_fallback_path() else {\n        return Err(std::io::Error::new(\n            std::io::ErrorKind::NotFound,\n            \"no home directory resolves; set GROK_COPY_FILE to enable the copy backup file\",\n        ));\n    };\n    #[cfg(unix)]\n    if let Some(parent) = path.parent()\n        && !parent.as_os_str().is_empty()\n    {\n        use std::os::unix::fs::DirBuilderExt;\n        std::fs::DirBuilder::new()\n            .recursive(true)\n            .mode(0o700)\n            .create(parent)?;\n    }\n    write_text_to_copy_file(text, &path)\n}\n\n/// Compose a [`CopyDelivery`] from the clipboard toast and the (always","sourceCodeStart":585,"sourceCodeEnd":621,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager-render/src/clipboard/mod.rs#L585-L621","documentation":"write_copy_fallback writes clipboard content to a backup file on disk; the backup path comes from default_copy_fallback_path() (GROK_COPY_FILE or a home-derived default). When no home directory resolves and no override is set, it returns this NotFound error instead of guessing a location, telling the user how to enable the feature.","triggerScenarios":"Calling write_copy_fallback (via copy_text_or_file) with GROK_COPY_FILE unset in an environment where the home directory cannot be resolved.","commonSituations":"Headless/CI/container environments lacking HOME; clipboard unavailable and the fallback path also unresolvable; typo'd GROK_COPY_FILE being empty so the default path is used.","solutions":["Set GROK_COPY_FILE to an explicit absolute file path and retry","Set HOME so the default fallback path (~/.grok/...) resolves","Check clipboard availability; on systems with a working clipboard the fallback is not needed","Create the parent directory (0700 on Unix) if GROK_COPY_FILE points at a new private dir"],"exampleFix":"// before\nwrite_copy_fallback(\"text\")?; // NotFound\n// after\nstd::env::set_var(\"GROK_COPY_FILE\", \"/tmp/grok-copy-backup.txt\");\nlet path = write_copy_fallback(\"text\")?;","handlingStrategy":"fallback","validationCode":"let usable = std::env::var_os(\"GROK_COPY_FILE\").is_some()\n    || std::env::var_os(\"HOME\").map(|h| !h.is_empty()).unwrap_or(false);\nif !usable { eprintln!(\"copy fallback disabled: set GROK_COPY_FILE\"); }","typeGuard":null,"tryCatchPattern":"match write_copy_fallback(text) {\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        eprintln!(\"copy backup unavailable; clipboard content not persisted\");\n    }\n    other => other?,\n}","preventionTips":["Set GROK_COPY_FILE explicitly in headless/container environments","Ensure HOME is set for the process","Pre-create the fallback parent directory with 0700 on Unix","Prefer the real clipboard and treat the fallback as last resort"],"tags":["clipboard","env","fallback","filesystem"],"backgroundTag":"missing-env-var","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}