Skip to content

Fix uncaught invalid arg#10318

Merged
abnegate merged 3 commits into1.7.xfrom
fix-catches
Aug 14, 2025
Merged

Fix uncaught invalid arg#10318
abnegate merged 3 commits into1.7.xfrom
fix-catches

Conversation

@abnegate
Copy link
Copy Markdown
Member

What does this PR do?

(Provide a description of what this PR does and why it's needed.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 14, 2025

📝 Walkthrough

Walkthrough

Two new InvalidArgumentException catch blocks were added to updateAttribute in app/controllers/api/databases.php (two locations), mapping that exception to GENERAL_ARGUMENT_INVALID while retaining existing TypeException handling (ATTRIBUTE_TYPE_INVALID). Both endpoints now set the event label to a generic "update" and include the target documentId in the event payload. tests/e2e/Services/Databases/DatabasesBase.php adds assertions that PATCH count increment/decrement calls with value: 0 return HTTP 400; the decrement test block calls the increment endpoint while expecting 400. No public API or function signatures were changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4b0d66 and 8455ded.

📒 Files selected for processing (1)
  • app/controllers/api/databases.php (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/controllers/api/databases.php
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-catches

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 14, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
git 2.45.3-r0 CVE-2025-48384 HIGH
git 2.45.3-r0 CVE-2025-48385 HIGH
git-init-template 2.45.3-r0 CVE-2025-48384 HIGH
git-init-template 2.45.3-r0 CVE-2025-48385 HIGH
icu 74.2-r0 CVE-2025-5222 HIGH
icu-data-en 74.2-r0 CVE-2025-5222 HIGH
icu-dev 74.2-r0 CVE-2025-5222 HIGH
icu-libs 74.2-r0 CVE-2025-5222 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
pyc 3.12.9-r0 CVE-2024-12718 HIGH
pyc 3.12.9-r0 CVE-2025-4138 HIGH
pyc 3.12.9-r0 CVE-2025-4330 HIGH
pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3 3.12.9-r0 CVE-2024-12718 HIGH
python3 3.12.9-r0 CVE-2025-4138 HIGH
python3 3.12.9-r0 CVE-2025-4330 HIGH
python3 3.12.9-r0 CVE-2025-4517 HIGH
python3-pyc 3.12.9-r0 CVE-2024-12718 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4138 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4330 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2024-12718 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4138 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4330 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4517 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 HIGH
stdlib 1.22.10 CVE-2025-47907 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
app/controllers/api/databases.php (1)

281-287: Bug: Incorrect parentheses break attribute type/filter validation

Both conditionals are currently evaluating the wrong expressions due to misplaced parentheses. They likely always evaluate truthy/falsy incorrectly and can reject valid updates or mask invalid ones.

Fix with:

-    if ($attribute->getAttribute(('type') !== $type)) {
+    if ($attribute->getAttribute('type') !== $type) {
         throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID);
     }

-    if ($attribute->getAttribute('type') === Database::VAR_STRING && $attribute->getAttribute(('filter') !== $filter)) {
+    if ($attribute->getAttribute('type') === Database::VAR_STRING && $attribute->getAttribute('filter') !== $filter) {
         throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID);
     }

Consider adding/adjusting tests that hit updateAttribute() with mismatched type and filter to prevent regressions.

🧹 Nitpick comments (3)
app/controllers/api/databases.php (2)

4554-4557: Catching InvalidArgumentException and mapping to GENERAL_ARGUMENT_INVALID is correct. Consider preserving the exception chain.

Good addition; it standardizes 0-value increments as a client error (400). Minor nit: preserve the original exception as "previous" to aid debugging and logs.

Apply this diff:

-        } catch (InvalidArgumentException $e) {
-            throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage());
+        } catch (InvalidArgumentException $e) {
+            throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage(), previous: $e);
         }

4633-4636: Same improvement for decrement: keep the exception chain.

Symmetric handling is good. Keep the previous exception to aid diagnostics.

Apply this diff:

-        } catch (InvalidArgumentException $e) {
-            throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage());
+        } catch (InvalidArgumentException $e) {
+            throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $e->getMessage(), previous: $e);
         }
tests/e2e/Services/Databases/DatabasesBase.php (1)

5572-5581: Zero-increment test is good; consider asserting mapped error type (GENERAL_ARGUMENT_INVALID).

To make the test more robust against regression in exception mapping, assert the error type as well.

         $inc3 = $this->client->call(Client::METHOD_PATCH, "/databases/$databaseId/collections/$collectionId/documents/$docId/count/increment", array_merge([
             'content-type' => 'application/json',
             'x-appwrite-project' => $this->getProject()['$id'],
         ]), [
             'value' => 0
         ]);
         $this->assertEquals(400, $inc3['headers']['status-code']);
+        $this->assertEquals(Exception::GENERAL_ARGUMENT_INVALID, $inc3['body']['type']);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a3ea1f and 1e9d153.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • app/controllers/api/databases.php (2 hunks)
  • tests/e2e/Services/Databases/DatabasesBase.php (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
app/controllers/api/databases.php (1)
src/Appwrite/Extend/Exception.php (1)
  • Exception (7-408)
tests/e2e/Services/Databases/DatabasesBase.php (2)
tests/e2e/Client.php (1)
  • Client (8-328)
src/Appwrite/Event/Event.php (1)
  • getProject (151-154)
🪛 PHPMD (2.15.0)
tests/e2e/Services/Databases/DatabasesBase.php

5704-5704: Avoid unused local variables such as '$docId'. (Unused Code Rules)

(UnusedLocalVariable)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (1)
app/controllers/api/databases.php (1)

4529-4547: Confirm DB adapter exception types for increase/decreaseDocumentAttribute

I couldn't find the implementations of increaseDocumentAttribute/decreaseDocumentAttribute in this repo (search returned only call sites) — I cannot confirm they throw only InvalidArgumentException for value=0. Please verify the DB adapter (likely external) and ensure controllers catch/map any additional unchecked exceptions.

Files/call sites to check and/or update if adapter throws other exceptions:

  • app/controllers/api/databases.php — increase block (≈ lines 4539–4556) and decrease block (≈ lines 4618–4636)
  • src/Appwrite/Platform/Workers/Webhooks.php:150
  • src/Appwrite/Platform/Workers/Deletes.php:660
  • src/Appwrite/Deletes/Targets.php:45
  • app/controllers/api/messaging.php:2538 and 2844
  • app/controllers/api/teams.php:631, 1284, 1387

Action requested:

  • Confirm which exception classes the DB implementation throws for invalid values (e.g., value=0).
  • If it can throw other unchecked exceptions, map them to API Exceptions (or add explicit catches) similar to existing mappings (ConflictException, NotFoundException, LimitException, TypeException, InvalidArgumentException).

@github-actions
Copy link
Copy Markdown

✨ Benchmark results

  • Requests per second: 1,019
  • Requests with 200 status code: 183,474
  • P99 latency: 0.17967345

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,019 987
200 183,474 177,667
P99 0.17967345 0.198313099

@abnegate abnegate merged commit 405aa7f into 1.7.x Aug 14, 2025
155 of 156 checks passed
@abnegate abnegate deleted the fix-catches branch August 14, 2025 08:13
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.

2 participants