fix: handle X509 certificate errors for Ollama on Windows

- Add specific error handling for X509 to PEM conversion errors
- Add certificate validation error messages to help Windows users
- Disable automatic retries in Ollama client for clearer error messages
- Add localized error messages for certificate issues

Fixes #9291
This commit is contained in:
Roo Code 2025-11-16 02:59:37 +00:00
parent 744f4bd4c8
commit fbcffc85fd
3 changed files with 26 additions and 2 deletions

View file

@ -36,11 +36,18 @@ export class OllamaHandler extends BaseProvider implements SingleCompletionHandl
headers["Authorization"] = `Bearer ${this.options.ollamaApiKey}`
}
const baseUrl = this.options.ollamaBaseUrl || "http://localhost:11434"
// For localhost connections, we may encounter certificate issues on Windows
// The error handler will catch and provide helpful messages for these cases
this.client = new OpenAI({
baseURL: (this.options.ollamaBaseUrl || "http://localhost:11434") + "/v1",
baseURL: baseUrl + "/v1",
apiKey: apiKey,
timeout: getApiRequestTimeout(),
defaultHeaders: headers,
dangerouslyAllowBrowser: false,
maxRetries: 0, // Disable automatic retries to get clearer error messages
})
}

View file

@ -27,6 +27,21 @@ export function handleOpenAIError(error: unknown, providerName: string): Error {
return new Error(i18n.t("common:errors.api.invalidKeyInvalidChars"))
}
// X509 to PEM conversion error - typically certificate validation issues on Windows
if (msg.includes("X509 to PEM conversion") || msg.includes("X509_to_PEM")) {
return new Error(i18n.t("common:errors.api.certificateError"))
}
// Certificate validation errors
if (
msg.includes("certificate") ||
msg.includes("CERT_") ||
msg.includes("self signed") ||
msg.includes("self-signed")
) {
return new Error(i18n.t("common:errors.api.certificateValidation"))
}
// For other Error instances, wrap with provider-specific prefix
return new Error(`${providerName} completion error: ${msg}`)
}

View file

@ -121,7 +121,9 @@
"authenticationRequired": "Roo provider requires cloud authentication. Please sign in to Roo Code Cloud."
},
"api": {
"invalidKeyInvalidChars": "API key contains invalid characters."
"invalidKeyInvalidChars": "API key contains invalid characters.",
"certificateError": "Certificate error when connecting to Ollama. For localhost connections, this is usually a false positive. Try restarting Ollama or check your certificate configuration.",
"certificateValidation": "Certificate validation failed. For local Ollama instances, ensure Ollama is running correctly. For remote instances, verify the SSL certificate is valid."
},
"manual_url_empty": "Please enter a valid callback URL",
"manual_url_no_query": "Invalid callback URL: missing query parameters",