Decode Gemini errors sent as a single object, not only as an array

オープン
#484 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
swift

調査の方向性

Read JSONResponseErrorDecoder.decodeErrorResponse(data:) and the existing testAsyncChatsThrowsStatusErrorForSingleGeminiErrorObject test added in #471. First verify whether Gemini's OpenAI-compatible endpoint returns errors as a single object; the issue says this is unconfirmed. If it does, update decoding and the test to expect GeminiAPIErrorResponse; done means the caller receives the Gemini error message for that response.

索引モデルが issue の本文から書いたものです。

説明

JSONResponseErrorDecoder recognizes a Gemini error only when it comes wrapped in an array:

[{"error": {"code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT"}}]

The same error sent as a single object isn't recognized:

{"error": {"code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT"}}

It isn't an APIErrorResponse either, because type is required. So the caller never sees the message:

  • Before #471, the body surfaced as a DecodingError about the expected result type.
  • With #471, a status of 400 or above surfaces as OpenAIError.statusError, which carries no body.

The single-object shape is Google's standard API error format, which the native Gemini API uses. Nobody has confirmed yet whether the OpenAI-compatible endpoint ever returns it.

Proposal

  • Check whether Gemini's OpenAI-compatible endpoint returns errors as a single object.
  • If it does, make JSONResponseErrorDecoder.decodeErrorResponse(data:) also try a single GeminiAPIErrorResponse, so the caller gets the message.
  • Update testAsyncChatsThrowsStatusErrorForSingleGeminiErrorObject (added in #471) to expect a GeminiAPIErrorResponse.
主要言語
Swift
スター
2.9k
フォーク
519
平均マージ
3日 12時間
マージ済み PR(30日)
11

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MacPaw/OpenAI のほかの issue

MacPaw/OpenAI の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。