Skip to content

Return specific error for unrecognized payload in GenerativeAIService#15693

Merged
paulb777 merged 7 commits intomainfrom
unrecognized-payload-error-6685444019425181574
Jan 9, 2026
Merged

Return specific error for unrecognized payload in GenerativeAIService#15693
paulb777 merged 7 commits intomainfrom
unrecognized-payload-error-6685444019425181574

Conversation

@google-labs-jules
Copy link
Contributor

@google-labs-jules google-labs-jules bot commented Jan 9, 2026

Return specific error for unrecognized payload in GenerativeAIService

This pull request refines the error handling mechanism within the GenerativeAIService by 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

  • New Error Type for Unrecognized Payloads: Introduced an UnrecognizedRPCError struct in FirebaseAI/Sources/Errors.swift to specifically handle cases where the GenerativeAIService receives an unexpected or malformed error payload from the RPC.
  • Improved Error Handling in GenerativeAIService: Modified the GenerativeAIService.swift to catch generic errors during RPC processing and convert them into the new UnrecognizedRPCError, encapsulating the raw response body for better diagnostic information.
  • New Unit Test Coverage: Added a new unit test file, FirebaseAI/Tests/Unit/GenerativeAIServiceTests.swift, which includes a test case to verify that the GenerativeAIService correctly throws UnrecognizedRPCError when an unexpected server response is encountered.

PR created automatically by Jules for task 6685444019425181574 started by @paulb777

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.
@google-labs-jules
Copy link
Contributor Author

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@danger-firebase-ios
Copy link

1 Warning
⚠️ Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.)

Generated by 🚫 Danger

google-labs-jules bot and others added 3 commits January 9, 2026 00:09
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.
@paulb777
Copy link
Member

paulb777 commented Jan 9, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

google-labs-jules bot and others added 3 commits January 9, 2026 01:47
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.
@paulb777
Copy link
Member

paulb777 commented Jan 9, 2026

/gemini summarize

@gemini-code-assist
Copy link
Contributor

Summary of Changes

This pull request refines the error handling mechanism within the GenerativeAIService by 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

  • New Error Type for Unrecognized Payloads: Introduced an UnrecognizedRPCError struct in FirebaseAI/Sources/Errors.swift to specifically handle cases where the GenerativeAIService receives an unexpected or malformed error payload from the RPC.
  • Improved Error Handling in GenerativeAIService: Modified the GenerativeAIService.swift to catch generic errors during RPC processing and convert them into the new UnrecognizedRPCError, encapsulating the raw response body for better diagnostic information.
  • New Unit Test Coverage: Added a new unit test file, FirebaseAI/Tests/Unit/GenerativeAIServiceTests.swift, which includes a test case to verify that the GenerativeAIService correctly throws UnrecognizedRPCError when an unexpected server response is encountered.

🧠 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
  • FirebaseAI/Sources/Errors.swift
    • Added UnrecognizedRPCError struct and its LocalizedError conformance to provide a specific error type for unrecognized RPC response payloads.
  • FirebaseAI/Sources/GenerativeAIService.swift
    • Modified the catch block in GenerativeAIService to convert generic errors from unrecognized response data into UnrecognizedRPCError, capturing the raw response body for better debugging.
  • FirebaseAI/Tests/Unit/GenerativeAIServiceTests.swift
    • Added a new test file containing GenerativeAIServiceTests to verify that the GenerativeAIService correctly throws UnrecognizedRPCError when an unexpected HTTP response body is received.
Activity
  • google-labs-jules[bot] initiated its presence, offering assistance and outlining its operational mode.
  • danger-firebase-ios[bot] flagged a warning regarding the absence of a changelog entry.
  • paulb777 invoked a /gemini review command.
  • gemini-code-assist[bot] provided a code suggestion to refactor a catch block in GenerativeAIServiceTests.swift for improved readability and conciseness.
  • paulb777 subsequently requested a /gemini summarize command.

@paulb777 paulb777 marked this pull request as ready for review January 9, 2026 03:42
@paulb777 paulb777 enabled auto-merge (squash) January 9, 2026 03:43
@paulb777 paulb777 requested a review from andrewheard January 9, 2026 03:43
Copy link
Contributor

@andrewheard andrewheard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for cleaning up a longstanding TODO!

@paulb777 paulb777 merged commit 7e1899f into main Jan 9, 2026
98 of 99 checks passed
@paulb777 paulb777 deleted the unrecognized-payload-error-6685444019425181574 branch January 9, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants