{"record":{"id":"294938bee603b3b3","repo":"zeroclaw-labs/zeroclaw","slug":"var-name-not-found-or-empty-in-env","errorCode":null,"errorMessage":"{var_name} not found or empty in .env","messagePattern":"(.+?) not found or empty in \\.env","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-tools/src/linkedin_client.rs","lineNumber":919,"sourceCode":"            .with_context(|| format!(\"Failed to read {}\", env_path.display()))?;\n\n        for line in content.lines() {\n            let line = line.trim();\n            if line.starts_with('#') || line.is_empty() {\n                continue;\n            }\n            let line = line.strip_prefix(\"export \").map(str::trim).unwrap_or(line);\n            if let Some((key, value)) = line.split_once('=')\n                && key.trim() == var_name\n            {\n                let val = LinkedInClient::parse_env_value(value);\n                if !val.is_empty() {\n                    return Ok(val);\n                }\n            }\n        }\n\n        anyhow::bail!(\"{var_name} not found or empty in .env\")\n    }\n\n    fn http_client() -> reqwest::Client {\n        zeroclaw_config::schema::build_runtime_proxy_client_with_timeouts(\n            \"tool.linkedin.image\",\n            60, // image gen can be slow\n            10,\n        )\n    }\n\n    // ── Stability AI ────────────────────────────────────────────\n\n    async fn try_stability(\n        &self,\n        prompt: &str,\n        output_dir: &Path,\n        base_name: &str,\n    ) -> anyhow::Result<PathBuf> {","sourceCodeStart":901,"sourceCodeEnd":937,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-tools/src/linkedin_client.rs#L901-L937","documentation":"read_env_var resolves a variable strictly from the workspace .env file (not the process environment), parsing KEY=VALUE lines with optional export prefixes, comments, and quoted values. It bails when the key is absent or its parsed value is empty; this is how the image providers surface 'no API key configured'.","triggerScenarios":"The key is missing from .env; the line is commented out; the value is empty or only quotes; the workspace_dir contains no .env; or the provider's api_key_env setting names a different variable than the one stored in the file.","commonSituations":"Keys injected via docker/CI environment instead of the file; .env stored one directory above the workspace; spelling drift between the api_key_env config and the file.","solutions":["Add an uncommented, non-empty KEY=value line to the .env inside the exact workspace_dir the client was constructed with","Compare the variable name against the provider's api_key_env setting in config","If you rely on process env vars, copy them into .env — this reader never consults the process environment"],"exampleFix":"# before\n# OPENAI_API_KEY=sk-...\nOPENAI_APIKEY=sk-...\n\n# after\nOPENAI_API_KEY=sk-...","handlingStrategy":"validation","validationCode":"fn env_var_present(dir: &Path, key: &str) -> anyhow::Result<()> {\n    let content = std::fs::read_to_string(dir.join(\".env\")).context(\"workspace .env missing\")?;\n    let ok = content.lines().any(|l| {\n        let l = l.trim().strip_prefix(\"export \").map(str::trim).unwrap_or(l.trim());\n        match l.split_once('=') {\n            Some((k, v)) => k.trim() == key && !v.trim().trim_matches('\"').trim_matches('\\'').is_empty(),\n            None => false,\n        }\n    });\n    anyhow::ensure!(ok, \"{key} missing or empty in .env\");\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"Catch and report as configuration: name the missing variable (it is embedded in the message) and the workspace path searched — do not retry until the file is fixed.","preventionTips":["Run a config check at startup that verifies every configured api_key_env resolves in the workspace .env","Do not rely on process env vars — this reader only looks at the file","Keep api_key_env names and .env keys in one place to avoid drift"],"tags":["env-file","configuration","api-key"],"backgroundTag":"missing-env-var","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}