Przeglądaj źródła

Improve error display

Christiaan Arnoldus 4 miesięcy temu
rodzic
commit
4f1c67cf82

+ 2 - 0
src/api/providers/kilocode/fetchWithTimeout.ts

@@ -1,5 +1,7 @@
 import * as undici from "undici"
 
+export const HeadersTimeoutError = undici.errors.HeadersTimeoutError
+
 export function fetchWithTimeout(timeoutMs: number, headers?: Record<string, string>): typeof fetch {
 	const agent = new undici.Agent({ headersTimeout: timeoutMs, bodyTimeout: timeoutMs })
 	return (input, init) => {

+ 10 - 3
src/api/providers/lm-studio.ts

@@ -13,7 +13,7 @@ import { ApiStream } from "../transform/stream"
 
 import { BaseProvider } from "./base-provider"
 import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from "../index"
-import { fetchWithTimeout } from "./kilocode/fetchWithTimeout"
+import { fetchWithTimeout, HeadersTimeoutError } from "./kilocode/fetchWithTimeout"
 
 import { getModels, getModelsFromCache } from "./fetchers/modelCache"
 import { handleOpenAIError } from "./utils/openai-error-handler"
@@ -31,8 +31,10 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
 		this.client = new OpenAI({
 			baseURL: (this.options.lmStudioBaseUrl || "http://localhost:1234") + "/v1",
 			apiKey: "noop",
-			timeout: timeout, // kilocode_change
-			fetch: fetchWithTimeout(timeout), // kilocode_change
+			// kilocode_change start
+			timeout: timeout,
+			fetch: fetchWithTimeout(timeout),
+			// kilocode_change end
 		})
 	}
 
@@ -138,6 +140,11 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
 				outputTokens,
 			} as const
 		} catch (error) {
+			// kilocode_change start
+			if (error.cause instanceof HeadersTimeoutError) {
+				throw new Error("Headers timeout", { cause: error })
+			}
+			// kilocode_change end
 			throw new Error(
 				"Please check the LM Studio developer logs to debug what went wrong. You may need to load the model with a larger context length to work with Kilo Code's prompts.",
 			)

+ 7 - 1
src/api/providers/native-ollama.ts

@@ -9,7 +9,7 @@ import { XmlMatcher } from "../../utils/xml-matcher"
 import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from "../index"
 
 // kilocode_change start
-import { fetchWithTimeout } from "./kilocode/fetchWithTimeout"
+import { fetchWithTimeout, HeadersTimeoutError } from "./kilocode/fetchWithTimeout"
 import { getApiRequestTimeout } from "./utils/timeout-config"
 
 const TOKEN_ESTIMATION_FACTOR = 4 //Industry standard technique for estimating token counts without actually implementing a parser/tokenizer
@@ -293,6 +293,12 @@ export class NativeOllamaHandler extends BaseProvider implements SingleCompletio
 			const statusCode = error.status || error.statusCode
 			const errorMessage = error.message || "Unknown error"
 
+			// kilocode_change start
+			if (error.cause instanceof HeadersTimeoutError) {
+				throw new Error("Headers timeout", { cause: error })
+			}
+			// kilocode_change end
+
 			if (error.code === "ECONNREFUSED") {
 				throw new Error(
 					`Ollama service is not running at ${this.options.ollamaBaseUrl || "http://localhost:11434"}. Please start Ollama first.`,