Skip to content

Bump SDK to v2.0 #761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Bump SDK to v2.0 #761

wants to merge 1 commit into from

Conversation

Strift
Copy link
Collaborator

@Strift Strift commented Jun 4, 2025

This is a draft PR to see CI results.

Related issue

See #749 for discussion regarding v2.0

Summary by CodeRabbit

  • Refactor

    • Replaced custom JSON encoding/decoding exceptions with the standard PHP \JsonException throughout the application.
    • Updated error messages related to JSON errors for clarity and consistency.
  • Tests

    • Adjusted tests to expect \JsonException and updated related error message assertions.

* Remove custom JSON exceptions

* Lint

* Update src/Http/Serialize/Json.php

Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>

---------

Co-authored-by: Tomas Norkūnas <norkunas.tom@gmail.com>
Copy link

coderabbitai bot commented Jun 4, 2025

Walkthrough

This change removes custom JSON exception classes and replaces their usage throughout the codebase with PHP's built-in \JsonException. All relevant docblocks, exception handling, and test expectations are updated accordingly. The custom exception classes are deleted, and their references are removed from imports and documentation.

Changes

Files/Groups Change Summary
src/Contracts/Http.php, src/Http/Serialize/SerializerInterface.php, src/Http/Client.php Updated docblocks to use @throws \JsonException instead of custom exceptions; removed related imports.
src/Exceptions/JsonEncodingException.php, src/Exceptions/JsonDecodingException.php Deleted custom exception classes.
src/Http/Serialize/Json.php Removed try-catch blocks and custom exception wrapping; now directly throws \JsonException.
tests/Endpoints/DocumentsTest.php, tests/Http/ClientTest.php, tests/Http/Serialize/JsonTest.php Updated tests to expect \JsonException and adjusted expected exception messages; removed custom exception imports.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Serializer (Json)
    participant PHP Engine

    Client->>Serializer (Json): serialize(data)
    Serializer (Json)->>PHP Engine: json_encode(data, JSON_THROW_ON_ERROR)
    alt On error
        PHP Engine-->>Client: throws \JsonException
    else Success
        PHP Engine-->>Serializer (Json): JSON string
        Serializer (Json)-->>Client: JSON string
    end
Loading

Possibly related PRs

  • meilisearch/meilisearch-php#759: The main PR and the retrieved PR both make identical changes to replace custom JSON exceptions with PHP's built-in \JsonException across the same files and methods, including updates to interface docblocks, exception class removals, and test adjustments.

Suggested labels

breaking-change

Suggested reviewers

  • brunoocasali
  • norkunas

Poem

A hop, a leap, a JSON cheer,
Custom exceptions disappear!
Now with PHP’s own in tow,
Errors are clearer—let them show!
Tests and docs all join the fun,
Simpler code for everyone.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a5bef7 and 8eb59e3.

📒 Files selected for processing (9)
  • src/Contracts/Http.php (1 hunks)
  • src/Exceptions/JsonDecodingException.php (0 hunks)
  • src/Exceptions/JsonEncodingException.php (0 hunks)
  • src/Http/Client.php (3 hunks)
  • src/Http/Serialize/Json.php (1 hunks)
  • src/Http/Serialize/SerializerInterface.php (2 hunks)
  • tests/Endpoints/DocumentsTest.php (1 hunks)
  • tests/Http/ClientTest.php (6 hunks)
  • tests/Http/Serialize/JsonTest.php (2 hunks)
💤 Files with no reviewable changes (2)
  • src/Exceptions/JsonDecodingException.php
  • src/Exceptions/JsonEncodingException.php
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/Http/Serialize/Json.php (1)
src/Http/Serialize/SerializerInterface.php (1)
  • unserialize (27-27)
🔇 Additional comments (14)
src/Http/Client.php (1)

84-84: LGTM! Exception documentation updated consistently.

The PHPDoc annotations have been correctly updated to use PHP's built-in \JsonException instead of custom JSON exceptions. This improves consistency and reduces maintenance overhead by leveraging standard PHP exceptions.

Also applies to: 105-105, 168-168

tests/Endpoints/DocumentsTest.php (1)

155-156: Test correctly updated for native JsonException.

The test expectations have been properly updated to use PHP's built-in \JsonException and its native error message. This change aligns with the removal of custom JSON exceptions throughout the codebase.

src/Http/Serialize/SerializerInterface.php (1)

16-16: Interface documentation properly updated.

The SerializerInterface correctly documents that serialize() and unserialize() methods now throw \JsonException instead of custom exceptions. This ensures implementing classes will use consistent exception handling.

Also applies to: 25-25

src/Contracts/Http.php (1)

13-13: HTTP interface documentation consistently updated.

All HTTP methods in the interface now correctly document \JsonException instead of custom JSON exceptions. This provides a consistent contract for implementations and aligns with the v2.0 refactoring to use standard PHP exceptions.

Also applies to: 21-21, 29-29, 35-35, 41-41

src/Http/Serialize/Json.php (2)

11-11: LGTM! Simplified exception handling.

The removal of custom exception wrapping and direct use of JSON_THROW_ON_ERROR simplifies the code while maintaining proper error handling with PHP's native \JsonException.


16-16: Good addition of JSON_BIGINT_AS_STRING flag.

The addition of JSON_BIGINT_AS_STRING flag is a valuable improvement that prevents precision loss for large integers by representing them as strings instead of PHP floats.

tests/Http/Serialize/JsonTest.php (2)

23-24: LGTM! Exception expectations updated correctly.

The test correctly expects PHP's native \JsonException with the appropriate error message for NaN/Inf encoding failures.


39-40: LGTM! Exception expectations updated correctly.

The test correctly expects PHP's native \JsonException with the appropriate syntax error message for malformed JSON.

tests/Http/ClientTest.php (6)

58-59: LGTM! Exception expectations updated correctly.

The test correctly expects PHP's native \JsonException for malformed UTF-8 characters in JSON encoding.


73-74: LGTM! Exception expectations updated correctly.

The test correctly expects PHP's native \JsonException for JSON syntax errors in response parsing.


105-106: LGTM! Exception expectations updated correctly.

The test correctly expects PHP's native \JsonException for malformed UTF-8 characters in PUT request body encoding.


120-121: LGTM! Exception expectations updated correctly.

The test correctly expects PHP's native \JsonException for JSON syntax errors in PUT response parsing.


152-153: LGTM! Exception expectations updated correctly.

The test correctly expects PHP's native \JsonException for malformed UTF-8 characters in PATCH request body encoding.


167-168: LGTM! Exception expectations updated correctly.

The test correctly expects PHP's native \JsonException for JSON syntax errors in PATCH response parsing.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Strift Strift marked this pull request as draft June 4, 2025 04:27
@Strift Strift linked an issue Jun 4, 2025 that may be closed by this pull request
@Strift Strift added this to the Meilisearch PHP v2 milestone Jun 4, 2025
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.

Version 2.0 mega issue
1 participant