{"record":{"id":"dc1db6d19fac6888","repo":"Hmbown/CodeWhale","slug":"could-not-be-parsed-safely","errorCode":null,"errorMessage":"{} could not be parsed safely","messagePattern":"(.+?) could not be parsed safely","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":2846,"sourceCode":"\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);\n            continue;\n        }\n        if std::env::var_os(&key).is_some() {\n            continue;\n        }\n\n        // SAFETY: this loader runs synchronously in `main` before the runtime\n        // owner or Tokio workers are spawned. No concurrent environment reader\n        // exists inside Codewhale, and later startup code treats this process\n        // environment as immutable.\n        unsafe { std::env::set_var(&key, value) };\n        report.loaded.insert(key);\n    }\n    Ok(report)","sourceCodeStart":2828,"sourceCodeEnd":2864,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L2828-L2864","documentation":"After UTF-8 validation, the `.env` is parsed with `dotenvy::from_read_iter`. Any parse error from dotenvy is collapsed into this single error so the library never partially applies credentials from a file it could not fully and safely parse.","triggerScenarios":"`dotenvy::from_read_iter` returns an `Err` — malformed lines, unterminated quotes, invalid escape sequences, or unsafe variable expansion constructs in the `.env`.","commonSituations":"Hand-edited `.env` with a stray quote, multi-line value without proper quoting, or copy-pasted shell syntax dotenvy cannot parse.","solutions":["Validate the file line by line; look for unbalanced quotes or malformed `KEY=value` entries.","Temporarily run `dotenvy` against the file (or a linter) to get the precise line number dotenvy reports.","Remove or quote special characters (`$`, backticks, newlines) that break the parser."],"exampleFix":"// before\nAPI_KEY=\"unterminated value\n// after\nAPI_KEY=\"escaped value\"","handlingStrategy":"validation","validationCode":"dotenvy::from_path_iter(\".env\").map(|i| i.for_each(|_| ()))\n    .expect(\".env must parse cleanly before Codewhale loads it\");","typeGuard":null,"tryCatchPattern":"match load_workspace_dotenv_credentials_from_path(&path) {\n    Err(e) if e.to_string().contains(\"could not be parsed safely\") => eprintln!(\"fix .env syntax: {e}\"),\n    other => other?,\n}","preventionTips":["Quote all values containing spaces, `#`, or `$`.","Lint `.env` files in CI with dotenvy or dotenv-linter.","Avoid multi-line values unless properly quoted."],"tags":["dotenv","parse","config"],"backgroundTag":"json-parse-error","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"}