Skip to content

Commit 4ac1b92

Browse files
committed
fix: improve proxy connection error detection and documentation
- Add proxy configuration detection utility - Show warning when http.electronFetch is disabled with proxy settings - Improve error messages to guide users to the solution - Add comprehensive proxy configuration documentation - Update README with link to proxy documentation Fixes #6991
1 parent 7ed833c commit 4ac1b92

File tree

5 files changed

+253
-4
lines changed

5 files changed

+253
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Make Roo Code work your way with:
105105
- [Custom Modes](https://docs.roocode.com/advanced-usage/custom-modes) for specialized tasks
106106
- [Local Models](https://docs.roocode.com/advanced-usage/local-models) for offline use
107107
- [Auto-Approval Settings](https://docs.roocode.com/advanced-usage/auto-approving-actions) for faster workflows
108+
- [Proxy Configuration](docs/PROXY_CONFIGURATION.md) for working with corporate proxies and VPNs
108109

109110
## Resources
110111

docs/PROXY_CONFIGURATION.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Proxy Configuration Guide
2+
3+
## Issue: Connection Errors with Proxy Settings
4+
5+
If you're experiencing "Connection error" messages when using Roo Code with a proxy (SOCKS5, HTTP proxy, or PAC file), this guide will help you resolve the issue.
6+
7+
## Problem
8+
9+
When VSCode is configured to use a proxy (via environment variables, settings, or command-line arguments), but the `http.electronFetch` setting is disabled (which is the default), the extension may fail to connect to API endpoints. This particularly affects:
10+
11+
- OpenAI API connections
12+
- OpenAI-compatible API providers
13+
- Other providers that use the native `fetch` API
14+
15+
## Symptoms
16+
17+
- Generic "Connection error" messages when trying to use the extension
18+
- Models populate correctly but chat completions fail
19+
- Network Logger shows requests but they don't reach the server
20+
- The same configuration works in other extensions (like Cline)
21+
22+
## Solution
23+
24+
### Option 1: Enable Electron Fetch (Recommended)
25+
26+
1. Open VSCode Settings (`Cmd/Ctrl + ,`)
27+
2. Search for `http.electronFetch`
28+
3. Check the box to enable the setting
29+
4. Restart VSCode
30+
5. Try using Roo Code again
31+
32+
### Option 2: Use Command Line
33+
34+
Add this to your VSCode settings.json:
35+
36+
```json
37+
{
38+
"http.electronFetch": true
39+
}
40+
```
41+
42+
### Option 3: Configure VSCode Launch
43+
44+
If you're launching VSCode with a PAC file, ensure both settings are configured:
45+
46+
```bash
47+
code --proxy-pac-url=http://localhost:8000/proxy.pac
48+
```
49+
50+
And enable `http.electronFetch` in settings.
51+
52+
## Why This Happens
53+
54+
VSCode has two different implementations for making HTTP requests:
55+
56+
1. **Node.js fetch** (default): Doesn't fully support all proxy configurations
57+
2. **Electron fetch**: Better proxy support but disabled by default
58+
59+
When `http.electronFetch` is `false` (default), extensions using the native fetch API may fail to route requests through your proxy correctly.
60+
61+
## Automatic Detection
62+
63+
Roo Code now automatically detects this configuration issue and will:
64+
65+
1. Show a warning notification when proxy settings are detected but `http.electronFetch` is disabled
66+
2. Provide helpful error messages when connection errors occur
67+
3. Suggest the appropriate fix based on your configuration
68+
69+
## Supported Proxy Types
70+
71+
With `http.electronFetch` enabled, the following proxy configurations are supported:
72+
73+
- HTTP/HTTPS proxies (via `http.proxy` setting or environment variables)
74+
- SOCKS5 proxies
75+
- PAC (Proxy Auto-Configuration) files
76+
- Environment variables: `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`
77+
78+
## Troubleshooting
79+
80+
If you're still experiencing issues after enabling `http.electronFetch`:
81+
82+
1. **Verify proxy settings**: Ensure your proxy configuration is correct
83+
2. **Check firewall rules**: Make sure VSCode is allowed through your firewall
84+
3. **Test connectivity**: Try accessing the API endpoint directly via curl or browser
85+
4. **Check API credentials**: Ensure your API keys are valid and have the necessary permissions
86+
5. **Review logs**: Check the Roo Code output channel for detailed error messages
87+
88+
## Alternative Solutions
89+
90+
If enabling `http.electronFetch` doesn't resolve your issue:
91+
92+
1. **Temporarily disable proxy**: If the proxy isn't required for the API endpoint
93+
2. **Use a different provider**: Some providers may work better with your proxy setup
94+
3. **Configure proxy exceptions**: Add API endpoints to your proxy bypass list
95+
96+
## Related Issues
97+
98+
- [VSCode Issue #12588](https://github.com/microsoft/vscode/issues/12588) - Original discussion about proxy support
99+
- [Roo Code Issue #6991](https://github.com/RooCodeInc/Roo-Code/issues/6991) - Specific issue about connection errors with proxies
100+
101+
## Need Help?
102+
103+
If you're still experiencing issues, please:
104+
105+
1. Open an issue on [GitHub](https://github.com/RooCodeInc/Roo-Code/issues)
106+
2. Include your proxy configuration (without sensitive information)
107+
3. Provide the error messages from the Roo Code output channel
108+
4. Mention whether `http.electronFetch` is enabled
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import * as vscode from "vscode"
2+
3+
/**
4+
* Detects if the user has proxy settings configured but http.electronFetch is disabled.
5+
* This combination can cause connection errors with certain API providers.
6+
*/
7+
export function detectProxyConfigurationIssue(): {
8+
hasProxyConfig: boolean
9+
electronFetchEnabled: boolean
10+
hasIssue: boolean
11+
proxySettings: string[]
12+
} {
13+
const config = vscode.workspace.getConfiguration()
14+
15+
// Check for proxy-related settings
16+
const httpProxy = config.get<string>("http.proxy")
17+
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy
18+
const httpProxyEnv = process.env.HTTP_PROXY || process.env.http_proxy
19+
const allProxy = process.env.ALL_PROXY || process.env.all_proxy
20+
21+
// Check if electronFetch is enabled (default is false in VSCode)
22+
const electronFetchEnabled = config.get<boolean>("http.electronFetch", false)
23+
24+
// Collect all proxy settings found
25+
const proxySettings: string[] = []
26+
if (httpProxy) proxySettings.push(`VSCode http.proxy: ${httpProxy}`)
27+
if (httpsProxy) proxySettings.push(`HTTPS_PROXY: ${httpsProxy}`)
28+
if (httpProxyEnv) proxySettings.push(`HTTP_PROXY: ${httpProxyEnv}`)
29+
if (allProxy) proxySettings.push(`ALL_PROXY: ${allProxy}`)
30+
31+
// Check if running with proxy PAC file
32+
const args = process.argv.join(" ")
33+
const hasPacFile = args.includes("--proxy-pac-url")
34+
if (hasPacFile) {
35+
const pacMatch = args.match(/--proxy-pac-url[= ]([^ ]+)/)
36+
if (pacMatch) {
37+
proxySettings.push(`PAC file: ${pacMatch[1]}`)
38+
}
39+
}
40+
41+
const hasProxyConfig = proxySettings.length > 0
42+
const hasIssue = hasProxyConfig && !electronFetchEnabled
43+
44+
return {
45+
hasProxyConfig,
46+
electronFetchEnabled,
47+
hasIssue,
48+
proxySettings,
49+
}
50+
}
51+
52+
/**
53+
* Formats a helpful error message when proxy configuration issues are detected
54+
*/
55+
export function formatProxyErrorMessage(
56+
error: any,
57+
proxyInfo?: ReturnType<typeof detectProxyConfigurationIssue>,
58+
): string {
59+
const baseError = error?.message || "Connection error"
60+
61+
if (!proxyInfo) {
62+
proxyInfo = detectProxyConfigurationIssue()
63+
}
64+
65+
if (proxyInfo.hasIssue) {
66+
return `${baseError}
67+
68+
⚠️ **Proxy Configuration Issue Detected**
69+
70+
You have proxy settings configured but \`http.electronFetch\` is disabled (default). This can cause connection errors with API providers.
71+
72+
**Detected proxy settings:**
73+
${proxyInfo.proxySettings.map((s) => `• ${s}`).join("\n")}
74+
75+
**Solution:**
76+
1. Open VSCode Settings (Cmd/Ctrl + ,)
77+
2. Search for "http.electronFetch"
78+
3. Enable the setting (check the box)
79+
4. Restart VSCode and try again
80+
81+
**Alternative solutions:**
82+
• Use a different API provider that works with your proxy setup
83+
• Configure the extension to use axios-based providers when available
84+
• Temporarily disable proxy settings if not needed
85+
86+
For more information, see: https://github.com/microsoft/vscode/issues/12588`
87+
}
88+
89+
// Check for other common connection errors
90+
if (baseError.includes("ECONNREFUSED")) {
91+
return `${baseError}
92+
93+
The connection was refused. Please check:
94+
• Is the API endpoint URL correct?
95+
• Is the service running and accessible?
96+
• Are there any firewall or network restrictions?`
97+
}
98+
99+
if (baseError.includes("ETIMEDOUT") || baseError.includes("ESOCKETTIMEDOUT")) {
100+
return `${baseError}
101+
102+
The connection timed out. Please check:
103+
• Is the API endpoint accessible from your network?
104+
• Are you behind a corporate firewall or VPN?
105+
• Is the service experiencing high load?`
106+
}
107+
108+
if (baseError.includes("ENOTFOUND")) {
109+
return `${baseError}
110+
111+
The hostname could not be resolved. Please check:
112+
• Is the API endpoint URL spelled correctly?
113+
• Do you have internet connectivity?
114+
• Are DNS settings configured correctly?`
115+
}
116+
117+
return baseError
118+
}
119+
120+
/**
121+
* Shows a warning notification if proxy configuration issues are detected
122+
*/
123+
export async function showProxyConfigurationWarning(): Promise<void> {
124+
const proxyInfo = detectProxyConfigurationIssue()
125+
126+
if (proxyInfo.hasIssue) {
127+
const message = "Proxy detected but http.electronFetch is disabled. This may cause connection errors."
128+
const action = await vscode.window.showWarningMessage(message, "Enable electronFetch", "Learn More", "Dismiss")
129+
130+
if (action === "Enable electronFetch") {
131+
// Open settings and navigate to the http.electronFetch setting
132+
await vscode.commands.executeCommand("workbench.action.openSettings", "http.electronFetch")
133+
} else if (action === "Learn More") {
134+
// Open the GitHub issue for more information
135+
await vscode.env.openExternal(vscode.Uri.parse("https://github.com/microsoft/vscode/issues/12588"))
136+
}
137+
}
138+
}

src/core/task/Task.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import delay from "delay"
99
import pWaitFor from "p-wait-for"
1010
import { serializeError } from "serialize-error"
1111

12+
import { detectProxyConfigurationIssue, formatProxyErrorMessage } from "../../api/providers/utils/proxy-detection"
1213
import {
1314
type TaskLike,
1415
type TaskEvents,
@@ -2221,10 +2222,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
22212222

22222223
return
22232224
} else {
2224-
const { response } = await this.ask(
2225-
"api_req_failed",
2226-
error.message ?? JSON.stringify(serializeError(error), null, 2),
2227-
)
2225+
const { response } = await this.ask("api_req_failed", formatProxyErrorMessage(error))
22282226

22292227
if (response !== "yesButtonClicked") {
22302228
// This will never happen since if noButtonClicked, we will

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { ContextProxy } from "./core/config/ContextProxy"
2424
import { ClineProvider } from "./core/webview/ClineProvider"
2525
import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
2626
import { TerminalRegistry } from "./integrations/terminal/TerminalRegistry"
27+
import { showProxyConfigurationWarning } from "./api/providers/utils/proxy-detection"
2728
import { McpServerManager } from "./services/mcp/McpServerManager"
2829
import { CodeIndexManager } from "./services/code-index/manager"
2930
import { MdmService } from "./services/mdm/MdmService"
@@ -81,6 +82,9 @@ export async function activate(context: vscode.ExtensionContext) {
8182
// Initialize i18n for internationalization support.
8283
initializeI18n(context.globalState.get("language") ?? formatLanguage(vscode.env.language))
8384

85+
// Check for proxy configuration issues and show warning if needed
86+
await showProxyConfigurationWarning()
87+
8488
// Initialize terminal shell execution handlers.
8589
TerminalRegistry.initialize()
8690

0 commit comments

Comments
 (0)