{"record":{"id":"d2ee07ca320f5d8c","repo":"pbakaus/impeccable","slug":"typeerror-fetch-failed","errorCode":null,"errorMessage":"TypeError: fetch failed: {}\n","messagePattern":"TypeError: fetch failed: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/context/src/generate_image.rs","lineNumber":357,"sourceCode":"        m.insert(\"model\".into(), Value::String(\"gpt-image-2\".into()));\n        m.insert(\"prompt\".into(), Value::String(prompt.clone()));\n        m.insert(\"size\".into(), Value::String(size.clone()));\n        m.insert(\"quality\".into(), Value::String(quality.clone()));\n        m.insert(\"n\".into(), Value::from(1));\n        agent\n            .post(\"https://api.openai.com/v1/images/generations\")\n            .set(\"Authorization\", &format!(\"Bearer {}\", key))\n            .set(\"content-type\", \"application/json\")\n            .send_string(&serde_json::to_string(&Value::Object(m)).unwrap())\n    };\n    let (status, text) = match response {\n        Ok(r) => {\n            let st = r.status();\n            (st, r.into_string().unwrap_or_default())\n        }\n        Err(ureq::Error::Status(code, r)) => (code, r.into_string().unwrap_or_default()),\n        Err(e) => {\n            io.err(&format!(\"TypeError: fetch failed: {}\\n\", e));\n            return 1;\n        }\n    };\n    if !(200..300).contains(&status) {\n        let snippet: String = text.chars().take(300).collect();\n        io.err(&format!(\"generate-image: API error {}: {}\\n\", status, snippet));\n        return 1;\n    }\n    let json: Value = serde_json::from_str(&text).unwrap_or(Value::Null);\n    let b64 = json.get(\"data\").and_then(|d| d.get(0)).and_then(|d| d.get(\"b64_json\")).and_then(|b| b.as_str()).filter(|s| !s.is_empty());\n    let Some(b64) = b64 else {\n        io.err(\"generate-image: no image in response\\n\");\n        return 1;\n    };\n    let bytes = base64_decode(b64);\n    let _ = std::fs::write(abs(&out), bytes);\n    // best-effort embed + sidecar\n    // JS-PARITY: generate-image.mjs#676 reports whether the embed actually","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/pbakaus/impeccable/blob/2bc2879276c1f321a53c4ca99d3371e411329b52/crates/context/src/generate_image.rs#L339-L375","documentation":"The HTTP request from generate-image to the OpenAI image API failed at the transport level (ureq returned a non-status error). The command formats it as a Node-style \"TypeError: fetch failed\" and exits 1. This is a connectivity problem, not an HTTP error response from the API.","triggerScenarios":"`ureq::Error` that is neither a status response nor a transport-success — DNS resolution failure, connection refused/timeout, TLS certificate error, proxy misconfiguration, or no network interface while POSTing to the images endpoint.","commonSituations":"Corporate proxy/firewall blocking api.openai.com; laptop offline or VPN down; DNS issues in containers; system clock skew causing TLS failures; IPv6-only environments that can't reach the endpoint.","solutions":["Check network connectivity: `curl -sS https://api.openai.com/v1/models -o /dev/null -w '%{http_code}'`.","Verify proxy settings (HTTPS_PROXY/HTTP_PROXY) are correct if behind a corporate proxy, and that the CA bundle is available for TLS.","Retry after confirming the network/VPN is up — transient DNS or connection failures resolve on their own.","Inspect the printed underlying ureq error for the specific cause (DNS, connect, TLS) and fix accordingly.","If in a container/sandbox, ensure outbound HTTPS egress to api.openai.com is allowed."],"exampleFix":"// before\nimpeccable generate-image --prompt \"...\" --out o.png\n// TypeError: fetch failed: dns error: ...\n// after\nexport HTTPS_PROXY=http://proxy.corp:8080\nimpeccable generate-image --prompt \"...\" --out o.png   # or run on a network with egress","handlingStrategy":"retry","validationCode":"// preflight reachability\nconst ok = spawnSync(\"curl\", [\"-sS\", \"-o\", \"/dev/null\", \"-w\", \"%{http_code}\", \"https://api.openai.com/v1/models\"]).status === 0;\nif (!ok) console.warn(\"api.openai.com unreachable; generate-image will fail\");","typeGuard":null,"tryCatchPattern":"for (let attempt = 1; attempt <= 3; attempt++) {\n  const r = spawnSync(\"impeccable\", [\"generate-image\", ...], { encoding: \"utf8\" });\n  if (r.status === 0) break;\n  if (r.stderr.includes(\"TypeError: fetch failed\") && attempt < 3) {\n    await new Promise(res => setTimeout(res, 2 ** attempt * 1000));\n    continue;\n  }\n  throw new Error(r.stderr);\n}","preventionTips":["Check VPN/proxy/firewall egress to api.openai.com before batch generation jobs.","Set HTTPS_PROXY correctly in corporate environments.","Retry transient network failures with exponential backoff.","Keep system clocks synced to avoid TLS failures."],"tags":["network","http","fetch"],"backgroundTag":"http-request-failed","analyzedSha":"2bc2879276c1f321a53c4ca99d3371e411329b52","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}