{"record":{"id":"e3f38fe4c01ad0cd","repo":"Hmbown/CodeWhale","slug":"is-not-valid-utf-8","errorCode":null,"errorMessage":"{} is not valid UTF-8","messagePattern":"(.+?) is not valid UTF-8","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":2832,"sourceCode":"            Err(error) if error.kind() == io::ErrorKind::NotFound => {}\n            Err(error) => {\n                return Err(anyhow!(\n                    \"could not inspect {}: {error}\",\n                    candidate.display()\n                ));\n            }\n        }\n        if ancestor == boundary {\n            break;\n        }\n    }\n    Ok(None)\n}\n\nfn load_workspace_dotenv_credentials_from_path(path: &Path) -> Result<WorkspaceDotenvReport> {\n    let contents = read_stable_workspace_dotenv(path)?;\n    let text = std::str::from_utf8(&contents)\n        .map_err(|_| anyhow!(\"{} is not valid UTF-8\", path.display()))?;\n    if dotenv_has_variable_expansion(text) {\n        bail!(\n            \"{} uses variable expansion; workspace .env values must be literal to prevent ambient-secret substitution\",\n            path.display()\n        );\n    }\n\n    let mut report = WorkspaceDotenvReport {\n        path: path.to_path_buf(),\n        ..WorkspaceDotenvReport::default()\n    };\n    let entries = dotenvy::from_read_iter(std::io::Cursor::new(contents))\n        .collect::<std::result::Result<Vec<_>, _>>()\n        .map_err(|_| anyhow!(\"{} could not be parsed safely\", path.display()))?;\n    for entry in entries {\n        let (key, value) = entry;\n        if !is_workspace_dotenv_credential_key(&key) {\n            report.ignored.insert(key);","sourceCodeStart":2814,"sourceCodeEnd":2850,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L2814-L2850","documentation":"Workspace `.env` credentials are parsed as UTF-8 text. If the file's bytes are not valid UTF-8 the loader refuses it with this error instead of lossily decoding, because credential values must round-trip exactly.","triggerScenarios":"`load_workspace_dotenv_credentials_from_path` reads a `.env` whose bytes fail `std::str::from_utf8` — e.g. a binary file, or one saved in UTF-16/Latin-1.","commonSituations":"A `.env` edited and saved by a Windows tool as UTF-16, or a placeholder/binary file mistakenly named `.env`.","solutions":["Re-save the `.env` as UTF-8 (without BOM is safest).","Check for binary content: `file .env` should report text.","Recreate the file with plain ASCII keys and values."],"exampleFix":"// before (shell)\niconv -f UTF-16 -t UTF-8 .env.utf16 > .env  # wrong encoding source\n// after\niconv -f UTF-16LE -t UTF-8 .env.utf16 > .env","handlingStrategy":"validation","validationCode":"let bytes = std::fs::read(\".env\")?;\nif std::str::from_utf8(&bytes).is_err() {\n    eprintln!(\".env is not UTF-8; re-save it as UTF-8\");\n}","typeGuard":"fn is_valid_utf8_file(path: &Path) -> bool {\n    std::fs::read(path).map(|b| std::str::from_utf8(&b).is_ok()).unwrap_or(false)\n}","tryCatchPattern":"match load_workspace_dotenv_credentials_from_path(&path) {\n    Err(e) if e.to_string().contains(\"not valid UTF-8\") => eprintln!(\"re-encode .env as UTF-8: {e}\"),\n    other => other?,\n}","preventionTips":["Configure editors/CI to save `.env` as UTF-8 without BOM.","Never generate `.env` from binary templates or PowerShell's default UTF-16 encoding.","Run `file .env` after generating the file to confirm it is text."],"tags":["dotenv","encoding","utf-8","config"],"backgroundTag":"invalid-argument-format","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}