Return specific error for unrecognized payload in GenerativeAIService#15693
Return specific error for unrecognized payload in GenerativeAIService#15693
Conversation
When the backend returns an error response that cannot be parsed as the expected `BackendError` JSON (e.g., HTML 500 error or malformed JSON), catch the decoding error and return a new `UnrecognizedRPCError` containing the raw response body. This helps in debugging by providing the actual content of the unrecognized error payload. - Add `UnrecognizedRPCError` struct to `Errors.swift`. - Update `GenerativeAIService.parseError(responseData:)` to return `UnrecognizedRPCError` on decoding failure. - Add unit test `GenerativeAIServiceTests.swift` to verify the new behavior.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Generated by 🚫 Danger |
When the backend returns an error response that cannot be parsed as the expected `BackendError` JSON (e.g., HTML 500 error or malformed JSON), catch the decoding error and return a new `UnrecognizedRPCError` containing the raw response body. This helps in debugging by providing the actual content of the unrecognized error payload. - Add `UnrecognizedRPCError` struct to `Errors.swift`. - Update `GenerativeAIService.parseError(responseData:)` to return `UnrecognizedRPCError` on decoding failure. - Add unit test `GenerativeAIServiceTests.swift` to verify the new behavior. - Ensure new files use copyright year 2026.
When the backend returns an error response that cannot be parsed as the expected `BackendError` JSON (e.g., HTML 500 error or malformed JSON), catch the decoding error and return a new `UnrecognizedRPCError` containing the raw response body. This helps in debugging by providing the actual content of the unrecognized error payload. - Add `UnrecognizedRPCError` struct to `Errors.swift`. - Update `GenerativeAIService.parseError(responseData:)` to return `UnrecognizedRPCError` on decoding failure. - Add unit test `GenerativeAIServiceTests.swift` to verify the new behavior, accounting for `MockURLProtocol` appending newlines. - Ensure new files use copyright year 2026.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a specific error, UnrecognizedRPCError, to handle cases where an error payload from the backend is not in the expected format. This is a valuable enhancement as it captures the raw response body, which is useful for debugging. The implementation is sound, and you've included a new unit test to validate this new error handling path, which is excellent. I have one minor suggestion to improve the readability of the new test.
When the backend returns an error response that cannot be parsed as the expected `BackendError` JSON (e.g., HTML 500 error or malformed JSON), catch the decoding error and return a new `UnrecognizedRPCError` containing the raw response body. This helps in debugging by providing the actual content of the unrecognized error payload. - Add `UnrecognizedRPCError` struct to `Errors.swift`. - Update `GenerativeAIService.parseError(responseData:)` to return `UnrecognizedRPCError` on decoding failure. - Add unit test `GenerativeAIServiceTests.swift` to verify the new behavior, accounting for `MockURLProtocol` appending newlines. - Ensure new files use copyright year 2026.
When the backend returns an error response that cannot be parsed as the expected `BackendError` JSON (e.g., HTML 500 error or malformed JSON), catch the decoding error and return a new `UnrecognizedRPCError` containing the raw response body. This helps in debugging by providing the actual content of the unrecognized error payload. - Add `UnrecognizedRPCError` struct to `Errors.swift`. - Update `GenerativeAIService.parseError(responseData:)` to return `UnrecognizedRPCError` on decoding failure. - Add unit test `GenerativeAIServiceTests.swift` to verify the new behavior, accounting for `MockURLProtocol` appending newlines and disabling the test on watchOS. - Ensure new files use copyright year 2026.
|
/gemini summarize |
Summary of ChangesThis pull request refines the error handling mechanism within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
|
andrewheard
left a comment
There was a problem hiding this comment.
LGTM. Thanks for cleaning up a longstanding TODO!
Return specific error for unrecognized payload in GenerativeAIService
This pull request refines the error handling mechanism within the
GenerativeAIServiceby introducing a dedicated error type,UnrecognizedRPCError, for situations where the service receives an unexpected or malformed error payload. This improvement provides clearer diagnostic information by including the raw response body directly within the error, which will aid developers in understanding and resolving issues related to unrecognized server responses.Highlights
UnrecognizedRPCErrorstruct inFirebaseAI/Sources/Errors.swiftto specifically handle cases where theGenerativeAIServicereceives an unexpected or malformed error payload from the RPC.GenerativeAIService.swiftto catch generic errors during RPC processing and convert them into the newUnrecognizedRPCError, encapsulating the raw response body for better diagnostic information.FirebaseAI/Tests/Unit/GenerativeAIServiceTests.swift, which includes a test case to verify that theGenerativeAIServicecorrectly throwsUnrecognizedRPCErrorwhen an unexpected server response is encountered.PR created automatically by Jules for task 6685444019425181574 started by @paulb777