{"record":{"id":"5d20e6fa94614e00","repo":"zeroclaw-labs/zeroclaw","slug":"linkedin-access-token-not-found-in-env-for-update","errorCode":null,"errorMessage":"LINKEDIN_ACCESS_TOKEN not found in .env for update","messagePattern":"LINKEDIN_ACCESS_TOKEN not found in \\.env for update","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-tools/src/linkedin_client.rs","lineNumber":800,"sourceCode":"                } else {\n                    new_token.to_string()\n                };\n\n                let new_line = if has_export {\n                    format!(\"export LINKEDIN_ACCESS_TOKEN={}\", new_val)\n                } else {\n                    format!(\"LINKEDIN_ACCESS_TOKEN={}\", new_val)\n                };\n\n                updated_lines.push(new_line);\n                found = true;\n            } else {\n                updated_lines.push(line.to_string());\n            }\n        }\n\n        if !found {\n            anyhow::bail!(\"LINKEDIN_ACCESS_TOKEN not found in .env for update\");\n        }\n\n        // Preserve trailing newline if original had one\n        let mut output = updated_lines.join(\"\\n\");\n        if content.ends_with('\\n') {\n            output.push('\\n');\n        }\n\n        tokio::fs::write(&env_path, &output)\n            .await\n            .with_context(|| format!(\"Failed to write {}\", env_path.display()))?;\n\n        Ok(())\n    }\n}\n\n// ── Image Generation ─────────────────────────────────────────────\n","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-tools/src/linkedin_client.rs#L782-L818","documentation":"update_env_token rewrites the workspace .env in place, replacing the value on the existing LINKEDIN_ACCESS_TOKEN line while preserving comments, quoting style, and neighboring keys. It refuses to invent the key: if no line defines LINKEDIN_ACCESS_TOKEN it bails, so a token refresh never silently strands the new token outside the file.","triggerScenarios":"Calling update_env_token when .env never contained the key (the process env var was used instead); the line was deleted or commented out; .env was regenerated from a template without the key; the client was built with a workspace_dir that does not contain the real .env.","commonSituations":"Fresh clones missing the .env template line; CI systems that inject environment variables instead of a file; scripts that rebuild .env from scratch and drop the token line.","solutions":["Add a LINKEDIN_ACCESS_TOKEN=... line to the workspace .env, then retry the refresh","If the value lives only in the process environment, write it into .env once so future updates have a line to rewrite","Confirm the workspace_dir passed to LinkedInClient is the directory that actually contains the .env being edited"],"exampleFix":"# before (.env has no token line)\nLINKEDIN_CLIENT_ID=...\nLINKEDIN_CLIENT_SECRET=...\n\n# after\nLINKEDIN_CLIENT_ID=...\nLINKEDIN_CLIENT_SECRET=...\nLINKEDIN_ACCESS_TOKEN=placeholder-will-be-rewritten-on-refresh","handlingStrategy":"validation","validationCode":"fn env_has_key(dir: &Path, key: &str) -> bool {\n    std::fs::read_to_string(dir.join(\".env\"))\n        .map(|c| c.lines().any(|l| {\n            let l = l.trim();\n            l.starts_with(&format!(\"{key}=\")) || l.starts_with(&format!(\"export {key}=\"))\n        }))\n        .unwrap_or(false)\n}\n\nif !env_has_key(&workspace_dir, \"LINKEDIN_ACCESS_TOKEN\") {\n    anyhow::bail!(\"refusing to refresh: no LINKEDIN_ACCESS_TOKEN line in .env\");\n}","typeGuard":null,"tryCatchPattern":"Catch and treat as a setup defect: stop the refresh flow, write the placeholder line into .env, and rerun — retrying unchanged will keep failing.","preventionTips":["Ship an .env template containing a commented LINKEDIN_ACCESS_TOKEN= line","Provision the key line before the first token refresh, not after","Construct LinkedInClient with the workspace_dir that owns the real .env"],"tags":["env-file","configuration","token-refresh","linkedin"],"backgroundTag":"missing-env-var","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}