WestManga: add JSON response validation and bump version#397
WestManga: add JSON response validation and bump version#397AhmadNaruto wants to merge 2 commits intoyuzono:masterfrom
Conversation
- Add validation for empty or malformed JSON responses - Throw IOException with descriptive message for invalid responses - Bump extVersionCode from 39 to 40 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Reviewer's GuideImplements defensive JSON response validation across all WestManga JSON-parsing endpoints and bumps the extension version code to 40 to reflect the behavioral change. Sequence diagram for JSON response validation in parsing methodssequenceDiagram
participant Server
participant OkHttpClient
participant WestManga
Server-->>OkHttpClient: HTTP JSON response
OkHttpClient-->>WestManga: Response
rect rgba(200,200,255,0.2)
WestManga->>WestManga: responseBody = response.body.string()
alt responseBody is blank OR not starting with '{'
WestManga-->>WestManga: throw IOException(Invalid JSON response from server. The website may have changed.)
else responseBody looks like JSON
WestManga->>WestManga: data = responseBody.parseAs<...>()
WestManga-->>OkHttpClient: Parsed result (MangasPage / SManga / List<SChapter> / List<Page>)
end
end
Class diagram for updated WestManga JSON parsing and validationclassDiagram
class HttpSource {
<<abstract>>
+searchMangaParse(response: Response) MangasPage
+mangaDetailsParse(response: Response) SManga
+chapterListParse(response: Response) List~SChapter~
+pageListParse(response: Response) List~Page~
}
class WestManga {
+searchMangaParse(response: Response) MangasPage
+mangaDetailsParse(response: Response) SManga
+chapterListParse(response: Response) List~SChapter~
+pageListParse(response: Response) List~Page~
-validateAndParsePaginatedBrowse(response: Response) PaginatedData~BrowseManga~
-validateAndParseManga(response: Response) Data~Manga~
-validateAndParseImageList(response: Response) Data~ImageList~
}
class Response {
+body: ResponseBody
}
class ResponseBody {
+string() String
}
class IOException
class PaginatedData~T~ {
+data: List~T~
}
class Data~T~ {
+data: T
}
class BrowseManga
class Manga {
+chapters: List~Chapter~
}
class ImageList {
+images: List~String~
}
class MangasPage
class SManga
class SChapter
class Page
class ExtensionsGradleConfig {
+extName: String
+extClass: String
+extVersionCode: Int
+isNsfw: Boolean
}
HttpSource <|-- WestManga
Response o-- ResponseBody
WestManga ..> IOException
WestManga ..> PaginatedData~BrowseManga~
WestManga ..> Data~Manga~
WestManga ..> Data~ImageList~
PaginatedData~T~ o-- BrowseManga
Data~T~ o-- Manga
Data~T~ o-- ImageList
Manga o-- Chapter
ImageList o-- Page
ExtensionsGradleConfig <.. WestManga
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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 the WestManga extension by introducing comprehensive validation for JSON responses received from the server. It ensures that the application can gracefully handle cases where the server returns empty or improperly formatted JSON, preventing crashes and providing clearer error messages to the user. Additionally, the extension's version code has been updated to reflect these changes. 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
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.
Hey - I've left some high level feedback:
- The JSON validation logic (reading body, checking blank/startsWith, throwing IOException) is duplicated across four parse methods; consider extracting this into a shared helper (e.g.,
fun <T> Response.safeParseAs(...)) to reduce repetition and keep future changes in one place. - Instead of only checking for a leading
{to detect invalid JSON, you might want to rely on the JSON parser in atry/catchblock so you also catch other malformed JSON cases (e.g., truncated content, wrong types) while still throwing the same descriptive IOException.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The JSON validation logic (reading body, checking blank/startsWith, throwing IOException) is duplicated across four parse methods; consider extracting this into a shared helper (e.g., `fun <T> Response.safeParseAs(...)`) to reduce repetition and keep future changes in one place.
- Instead of only checking for a leading `{` to detect invalid JSON, you might want to rely on the JSON parser in a `try/catch` block so you also catch other malformed JSON cases (e.g., truncated content, wrong types) while still throwing the same descriptive IOException.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces validation for JSON responses, which is a valuable addition to make the extension more robust against empty or malformed server responses. I've noticed that the validation logic is duplicated in four separate methods. To improve code quality and maintainability, I've provided a suggestion to refactor this duplicated code into a single private helper function. The version bump is correct.
src/id/westmanga/src/eu/kanade/tachiyomi/extension/id/westmanga/WestManga.kt
Outdated
Show resolved
Hide resolved
…a/WestManga.kt Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Checklist:
extVersionCodevalue inbuild.gradlefor individual extensionsoverrideVersionCodeorbaseVersionCodeas needed for all multisrc extensionsisNsfw = trueflag inbuild.gradlewhen appropriateidif a source's name or language were changedweb_hi_res_512.pngwhen adding a new extensionSummary by Sourcery
Validate JSON responses for the WestManga extension and update its version code.
Bug Fixes:
Build: