feat: add error handling for fetch operations in i18n

- Add new error messages for fetch operations
- Rename `errInvalidLocationFormat` to `errInvalidLocationFormatKey`
- Use `errors.New` instead of `fmt.Errorf` for fetch errors
- Update Chinese locale with fetch-related error messages
This commit is contained in:
Kayvan Sylvan
2026-02-16 08:38:35 -08:00
parent eeb9567ce0
commit c797a84847
3 changed files with 15 additions and 5 deletions

View File

@@ -481,5 +481,15 @@
"bedrock_converse_failed": "模型 %s 的 bedrock converse 失败:%w",
"bedrock_unexpected_response_type": "意外的响应类型:%T",
"bedrock_empty_response_content": "空响应内容",
"bedrock_unexpected_content_block_type": "意外的内容块类型:%T"
"bedrock_unexpected_content_block_type": "意外的内容块类型:%T",
"fetch_unknown_operation": "fetch未知操作 %q支持get",
"fetch_content_not_utf8": "fetch内容不是有效的 UTF-8 文本",
"fetch_content_null_bytes": "fetch内容包含空字节",
"fetch_error_create_request": "fetch创建请求时出错%v",
"fetch_error_fetching_url": "fetch获取 URL 时出错:%v",
"fetch_http_error": "fetchHTTP 错误:%d - %s",
"fetch_content_too_large": "fetch内容过大%d 字节(最大 %d 字节)",
"fetch_unsupported_content_type": "fetch不支持的内容类型 %q - 仅允许文本内容",
"fetch_error_reading_response": "fetch读取响应时出错%v",
"fetch_content_exceeds_limit": "fetch内容过大超过 %d 字节"
}

View File

@@ -31,7 +31,7 @@ const (
)
const (
errInvalidLocationFormat = "gemini_invalid_location_format"
errInvalidLocationFormatKey = "gemini_invalid_location_format"
locationSeparator = "/"
langCodeSeparator = "_"
langCodeNormalizedSep = "-"
@@ -232,7 +232,7 @@ func (o *Client) buildGenerateContentConfig(opts *domain.ChatOptions) (*genai.Ge
RetrievalConfig: &genai.RetrievalConfig{LanguageCode: loc},
}
} else {
return nil, fmt.Errorf(i18n.T(errInvalidLocationFormat), loc)
return nil, fmt.Errorf(i18n.T(errInvalidLocationFormatKey), loc)
}
}
}

View File

@@ -72,11 +72,11 @@ func (p *FetchPlugin) validateTextContent(content []byte) error {
debugf("Fetch: validating content length=%d bytes", len(content))
if !utf8.Valid(content) {
return fmt.Errorf(i18n.T("fetch_content_not_utf8"))
return errors.New(i18n.T("fetch_content_not_utf8"))
}
if bytes.Contains(content, []byte{0}) {
return fmt.Errorf(i18n.T("fetch_content_null_bytes"))
return errors.New(i18n.T("fetch_content_null_bytes"))
}
debugf("Fetch: content validation successful")