From 305c7479a589e7877074588b6467321f0a49cbdf Mon Sep 17 00:00:00 2001 From: tanaka takashi Date: Tue, 1 Sep 2026 20:52:08 +0900 Subject: fix: diagnosable translation errors and icon hidden after scroll MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translation error ("設定値が不正です") diagnosis - The INVALID_SETTINGS code collapsed two unrelated failures into one opaque message: (a) no model configured in the background settings cache, and (b) HTTP 400/403 from Ollama with the actual reason in the response body. Verified against a live Ollama server: the configured cloud models (glm-5.3:cloud etc.) stream fine from a plain page, so the generic message gave no clue which path fired. - ollama-client.js: read the Ollama error body on non-OK responses and append its message ("model is required" etc.) to the thrown error - message-router.js: no-model-configured now has its own explicit message ("モデルが設定されていません...") and concrete detail reasons are appended to the base message in the popover, e.g. 設定値が不正です。... (Ollama /api/chat failed: 400 - ...) Action icon disappearing - The scroll handler hid the action button whenever the popover was hidden, even with a live selection, leaving no way to translate until the user re-selected. It now repositions the icon while a selection exists and only hides it when the selection is gone (Design 5.4). Results: 73 passed, 0 failed. dist rebuilt. --- src/background/ollama-client.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/background/ollama-client.js') diff --git a/src/background/ollama-client.js b/src/background/ollama-client.js index 0286230..e53d997 100644 --- a/src/background/ollama-client.js +++ b/src/background/ollama-client.js @@ -15,6 +15,24 @@ import { isValidOllamaHost } from '../shared/settings-schema.js'; import { ERROR_CODES } from '../shared/constants.js'; +/** + * Extract a short error message from an Ollama JSON error body. + * @param {string} raw + * @returns {string} message or '' when not parseable + */ +function extractOllamaError(raw) { + if (!raw) return ''; + try { + const parsed = JSON.parse(raw); + if (parsed && typeof parsed.error === 'string') { + return parsed.error.slice(0, 200); + } + } catch { + // not JSON + } + return ''; +} + /** * Translate a fetch/HTTP failure into a stable error code. * @param {Response|undefined} response @@ -73,7 +91,9 @@ export async function listModels(host, signal) { throw toExtensionError(error); } if (!response.ok) { - const e = new Error(`Ollama /api/tags failed: ${response.status}`); + const detail = await response.text().catch(() => ''); + const serverMessage = extractOllamaError(detail); + const e = new Error(`Ollama /api/tags failed: ${response.status}${serverMessage ? ` - ${serverMessage}` : ''}`); e.code = response.status === 404 ? ERROR_CODES.MODEL_NOT_FOUND : ERROR_CODES.STREAM_ERROR; throw e; } @@ -119,7 +139,9 @@ export async function chatStream({ host, model, messages, think, options, onChun } if (!response.ok) { - const e = new Error(`Ollama /api/chat failed: ${response.status}`); + const detail = await response.text().catch(() => ''); + const serverMessage = extractOllamaError(detail); + const e = new Error(`Ollama /api/chat failed: ${response.status}${serverMessage ? ` - ${serverMessage}` : ''}`); e.code = response.status === 404 ? ERROR_CODES.MODEL_NOT_FOUND -- cgit v1.2.3