fix(patch): cherry-pick 936f624 to release/v0.33.0-preview.9-pr-21702 to patch version v0.33.0-preview.9 and create version 0.33.0-preview.10#21800
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of Google API error parsing by introducing mechanisms to handle JSON corruption caused by Server-Sent Events (SSE) serialization. It ensures that error messages and domain information can be correctly interpreted despite the presence of stray characters, thereby improving the reliability of error classification and user feedback. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request cherry-picks a fix for handling corrupted Google API error responses from SSE streams. The changes introduce sanitization logic to handle stray commas in JSON responses and corrupted characters in domain name strings within the error details.
My review focuses on the robustness of the new sanitization logic. I've found a potential issue in the sanitizeJsonString function where certain patterns of corruption could still result in invalid JSON. I've provided a suggestion for a more robust and efficient implementation. The other changes, including the domain sanitization and the new tests, look good.
| function sanitizeJsonString(jsonStr: string): string { | ||
| // Match a comma, optional whitespace/newlines, then another comma. | ||
| // Replace with just a comma + the captured whitespace. | ||
| // Loop to handle cases like `,,,` which would otherwise become `,,` on a single pass. | ||
| let prev: string; | ||
| do { | ||
| prev = jsonStr; | ||
| jsonStr = jsonStr.replace(/,(\s*),/g, ',$1'); | ||
| } while (jsonStr !== prev); | ||
| return jsonStr; | ||
| } |
There was a problem hiding this comment.
The current implementation is not fully robust. For an input with multiple stray commas separated by whitespace, like {"key": 1, , , 2}, it can produce invalid JSON. The issue is that preserving whitespace between commas can lead to an invalid structure.
A more robust and efficient solution is to use a single regular expression to replace any sequence of commas and intermittent whitespace with a single comma. This avoids the loop and correctly sanitizes more complex corruption patterns.
function sanitizeJsonString(jsonStr: string): string {
// This regex finds a comma followed by one or more groups of
// (optional whitespace and another comma). It replaces the entire
// sequence with a single comma. This handles cases like `, ,` or `,,,`
// in a single pass without a loop.
return jsonStr.replace(/,(\s*,)+/g, ',');
}|
Size Change: +292 B (0%) Total Size: 25.9 MB ℹ️ View Unchanged
|
This PR automatically cherry-picks commit 936f624 to patch version v0.33.0-preview.9 in the preview release to create version 0.33.0-preview.10.