Skip to content

WestManga: add JSON response validation and bump version#397

Open
AhmadNaruto wants to merge 2 commits intoyuzono:masterfrom
AhmadNaruto:westmanga-fix-clean3
Open

WestManga: add JSON response validation and bump version#397
AhmadNaruto wants to merge 2 commits intoyuzono:masterfrom
AhmadNaruto:westmanga-fix-clean3

Conversation

@AhmadNaruto
Copy link

@AhmadNaruto AhmadNaruto commented Mar 9, 2026

  • Add validation for empty or malformed JSON responses
  • Throw IOException with descriptive message for invalid responses
  • Bump extVersionCode from 39 to 40

Checklist:

  • Updated extVersionCode value in build.gradle for individual extensions
  • Updated overrideVersionCode or baseVersionCode as needed for all multisrc extensions
  • Referenced all related issues in the PR body (e.g. "Closes #xyz")
  • Added the isNsfw = true flag in build.gradle when appropriate
  • Have not changed source names
  • Have explicitly kept the id if a source's name or language were changed
  • Have tested the modifications by compiling and running the extension through Android Studio
  • Have removed web_hi_res_512.png when adding a new extension

Summary by Sourcery

Validate JSON responses for the WestManga extension and update its version code.

Bug Fixes:

  • Add checks for empty or non-JSON server responses and throw descriptive IOExceptions to surface potential site changes instead of failing silently.

Build:

  • Bump WestManga extension extVersionCode from 39 to 40.

- 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>
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 9, 2026

Reviewer's Guide

Implements 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 methods

sequenceDiagram
    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
Loading

Class diagram for updated WestManga JSON parsing and validation

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Validate JSON HTTP responses before parsing and throw descriptive IOExceptions on invalid content.
  • Replace direct use of response.parseAs() with manual extraction of response.body.string() in search, details, chapter list, and page list parsers.
  • Add a blank-or-non-JSON guard that checks for an empty body or a body not starting with '{' after trimming leading whitespace.
  • Throw IOException with a clear message when the validation fails, preventing silent parsing failures and signaling possible site changes.
  • Invoke parseAs() on the validated raw response string instead of the Response object to preserve existing mapping behavior.
src/id/westmanga/src/eu/kanade/tachiyomi/extension/id/westmanga/WestManga.kt
Update WestManga extension version to reflect the new validation behavior.
  • Increment extVersionCode from 39 to 40 to ship the JSON validation change.
src/id/westmanga/build.gradle

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • JSON Response Validation: Added validation checks for empty or malformed JSON responses from the server in various parsing functions.
  • Error Handling: Implemented throwing an IOException with a descriptive message when an invalid JSON response is detected, indicating a potential change in the website's structure.
  • Version Bump: Increased the extVersionCode from 39 to 40 for the WestManga extension.

🧠 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
  • src/id/westmanga/build.gradle
    • Updated extVersionCode from 39 to 40.
  • src/id/westmanga/src/eu/kanade/tachiyomi/extension/id/westmanga/WestManga.kt
    • Imported java.io.IOException for error handling.
    • Added validation for blank or non-JSON starting responses in searchMangaParse and throws IOException.
    • Added validation for blank or non-JSON starting responses in mangaDetailsParse and throws IOException.
    • Added validation for blank or non-JSON starting responses in chapterListParse and throws IOException.
    • Added validation for blank or non-JSON starting responses in pageListParse and throws IOException.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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 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.

…a/WestManga.kt

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant