mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
refactor: remove fragile proxy detection in favor of documentation
- Remove automatic proxy detection logic from extension startup - Remove proxy-detection.ts utility file - Simplify error messages to suggest enabling http.electronFetch when connection issues occur - Update documentation to focus on the solution rather than detection As suggested by @bstrdsmkr, the proxy detection approach was fragile. VSCode extensions cannot directly use Electron fetch - they can only suggest users enable the http.electronFetch setting which tells VSCode itself to use Electron fetch internally.
This commit is contained in:
parent
4ac1b926b4
commit
d25f7bb1d9
4 changed files with 13 additions and 152 deletions
|
|
@ -58,14 +58,6 @@ VSCode has two different implementations for making HTTP requests:
|
|||
|
||||
When `http.electronFetch` is `false` (default), extensions using the native fetch API may fail to route requests through your proxy correctly.
|
||||
|
||||
## Automatic Detection
|
||||
|
||||
Roo Code now automatically detects this configuration issue and will:
|
||||
|
||||
1. Show a warning notification when proxy settings are detected but `http.electronFetch` is disabled
|
||||
2. Provide helpful error messages when connection errors occur
|
||||
3. Suggest the appropriate fix based on your configuration
|
||||
|
||||
## Supported Proxy Types
|
||||
|
||||
With `http.electronFetch` enabled, the following proxy configurations are supported:
|
||||
|
|
|
|||
|
|
@ -1,138 +0,0 @@
|
|||
import * as vscode from "vscode"
|
||||
|
||||
/**
|
||||
* Detects if the user has proxy settings configured but http.electronFetch is disabled.
|
||||
* This combination can cause connection errors with certain API providers.
|
||||
*/
|
||||
export function detectProxyConfigurationIssue(): {
|
||||
hasProxyConfig: boolean
|
||||
electronFetchEnabled: boolean
|
||||
hasIssue: boolean
|
||||
proxySettings: string[]
|
||||
} {
|
||||
const config = vscode.workspace.getConfiguration()
|
||||
|
||||
// Check for proxy-related settings
|
||||
const httpProxy = config.get<string>("http.proxy")
|
||||
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy
|
||||
const httpProxyEnv = process.env.HTTP_PROXY || process.env.http_proxy
|
||||
const allProxy = process.env.ALL_PROXY || process.env.all_proxy
|
||||
|
||||
// Check if electronFetch is enabled (default is false in VSCode)
|
||||
const electronFetchEnabled = config.get<boolean>("http.electronFetch", false)
|
||||
|
||||
// Collect all proxy settings found
|
||||
const proxySettings: string[] = []
|
||||
if (httpProxy) proxySettings.push(`VSCode http.proxy: ${httpProxy}`)
|
||||
if (httpsProxy) proxySettings.push(`HTTPS_PROXY: ${httpsProxy}`)
|
||||
if (httpProxyEnv) proxySettings.push(`HTTP_PROXY: ${httpProxyEnv}`)
|
||||
if (allProxy) proxySettings.push(`ALL_PROXY: ${allProxy}`)
|
||||
|
||||
// Check if running with proxy PAC file
|
||||
const args = process.argv.join(" ")
|
||||
const hasPacFile = args.includes("--proxy-pac-url")
|
||||
if (hasPacFile) {
|
||||
const pacMatch = args.match(/--proxy-pac-url[= ]([^ ]+)/)
|
||||
if (pacMatch) {
|
||||
proxySettings.push(`PAC file: ${pacMatch[1]}`)
|
||||
}
|
||||
}
|
||||
|
||||
const hasProxyConfig = proxySettings.length > 0
|
||||
const hasIssue = hasProxyConfig && !electronFetchEnabled
|
||||
|
||||
return {
|
||||
hasProxyConfig,
|
||||
electronFetchEnabled,
|
||||
hasIssue,
|
||||
proxySettings,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a helpful error message when proxy configuration issues are detected
|
||||
*/
|
||||
export function formatProxyErrorMessage(
|
||||
error: any,
|
||||
proxyInfo?: ReturnType<typeof detectProxyConfigurationIssue>,
|
||||
): string {
|
||||
const baseError = error?.message || "Connection error"
|
||||
|
||||
if (!proxyInfo) {
|
||||
proxyInfo = detectProxyConfigurationIssue()
|
||||
}
|
||||
|
||||
if (proxyInfo.hasIssue) {
|
||||
return `${baseError}
|
||||
|
||||
⚠️ **Proxy Configuration Issue Detected**
|
||||
|
||||
You have proxy settings configured but \`http.electronFetch\` is disabled (default). This can cause connection errors with API providers.
|
||||
|
||||
**Detected proxy settings:**
|
||||
${proxyInfo.proxySettings.map((s) => `• ${s}`).join("\n")}
|
||||
|
||||
**Solution:**
|
||||
1. Open VSCode Settings (Cmd/Ctrl + ,)
|
||||
2. Search for "http.electronFetch"
|
||||
3. Enable the setting (check the box)
|
||||
4. Restart VSCode and try again
|
||||
|
||||
**Alternative solutions:**
|
||||
• Use a different API provider that works with your proxy setup
|
||||
• Configure the extension to use axios-based providers when available
|
||||
• Temporarily disable proxy settings if not needed
|
||||
|
||||
For more information, see: https://github.com/microsoft/vscode/issues/12588`
|
||||
}
|
||||
|
||||
// Check for other common connection errors
|
||||
if (baseError.includes("ECONNREFUSED")) {
|
||||
return `${baseError}
|
||||
|
||||
The connection was refused. Please check:
|
||||
• Is the API endpoint URL correct?
|
||||
• Is the service running and accessible?
|
||||
• Are there any firewall or network restrictions?`
|
||||
}
|
||||
|
||||
if (baseError.includes("ETIMEDOUT") || baseError.includes("ESOCKETTIMEDOUT")) {
|
||||
return `${baseError}
|
||||
|
||||
The connection timed out. Please check:
|
||||
• Is the API endpoint accessible from your network?
|
||||
• Are you behind a corporate firewall or VPN?
|
||||
• Is the service experiencing high load?`
|
||||
}
|
||||
|
||||
if (baseError.includes("ENOTFOUND")) {
|
||||
return `${baseError}
|
||||
|
||||
The hostname could not be resolved. Please check:
|
||||
• Is the API endpoint URL spelled correctly?
|
||||
• Do you have internet connectivity?
|
||||
• Are DNS settings configured correctly?`
|
||||
}
|
||||
|
||||
return baseError
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a warning notification if proxy configuration issues are detected
|
||||
*/
|
||||
export async function showProxyConfigurationWarning(): Promise<void> {
|
||||
const proxyInfo = detectProxyConfigurationIssue()
|
||||
|
||||
if (proxyInfo.hasIssue) {
|
||||
const message = "Proxy detected but http.electronFetch is disabled. This may cause connection errors."
|
||||
const action = await vscode.window.showWarningMessage(message, "Enable electronFetch", "Learn More", "Dismiss")
|
||||
|
||||
if (action === "Enable electronFetch") {
|
||||
// Open settings and navigate to the http.electronFetch setting
|
||||
await vscode.commands.executeCommand("workbench.action.openSettings", "http.electronFetch")
|
||||
} else if (action === "Learn More") {
|
||||
// Open the GitHub issue for more information
|
||||
await vscode.env.openExternal(vscode.Uri.parse("https://github.com/microsoft/vscode/issues/12588"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ import delay from "delay"
|
|||
import pWaitFor from "p-wait-for"
|
||||
import { serializeError } from "serialize-error"
|
||||
|
||||
import { detectProxyConfigurationIssue, formatProxyErrorMessage } from "../../api/providers/utils/proxy-detection"
|
||||
import {
|
||||
type TaskLike,
|
||||
type TaskEvents,
|
||||
|
|
@ -2222,7 +2221,19 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
|
|||
|
||||
return
|
||||
} else {
|
||||
const { response } = await this.ask("api_req_failed", formatProxyErrorMessage(error))
|
||||
let errorMsg = error.message || "API request failed"
|
||||
|
||||
// Add helpful message about proxy configuration if relevant
|
||||
if (
|
||||
errorMsg.includes("ECONNREFUSED") ||
|
||||
errorMsg.includes("ETIMEDOUT") ||
|
||||
errorMsg.includes("ENOTFOUND")
|
||||
) {
|
||||
errorMsg +=
|
||||
"\n\nIf you're behind a proxy, try enabling the 'http.electronFetch' setting in VSCode:\n1. Open Settings (Cmd/Ctrl + ,)\n2. Search for 'http.electronFetch'\n3. Enable the setting\n4. Restart VSCode"
|
||||
}
|
||||
|
||||
const { response } = await this.ask("api_req_failed", errorMsg)
|
||||
|
||||
if (response !== "yesButtonClicked") {
|
||||
// This will never happen since if noButtonClicked, we will
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import { ContextProxy } from "./core/config/ContextProxy"
|
|||
import { ClineProvider } from "./core/webview/ClineProvider"
|
||||
import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
|
||||
import { TerminalRegistry } from "./integrations/terminal/TerminalRegistry"
|
||||
import { showProxyConfigurationWarning } from "./api/providers/utils/proxy-detection"
|
||||
import { McpServerManager } from "./services/mcp/McpServerManager"
|
||||
import { CodeIndexManager } from "./services/code-index/manager"
|
||||
import { MdmService } from "./services/mdm/MdmService"
|
||||
|
|
@ -82,9 +81,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
// Initialize i18n for internationalization support.
|
||||
initializeI18n(context.globalState.get("language") ?? formatLanguage(vscode.env.language))
|
||||
|
||||
// Check for proxy configuration issues and show warning if needed
|
||||
await showProxyConfigurationWarning()
|
||||
|
||||
// Initialize terminal shell execution handlers.
|
||||
TerminalRegistry.initialize()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue