Skip to content
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

fix: resilience evidence attachment missing #1455

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Axxiar
Copy link
Contributor

@Axxiar Axxiar commented Jan 30, 2025

avoid crashing when the attachment is brutally removed from /db/attachments/

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved attachment handling to prevent errors when accessing non-existent files
    • Enhanced error detection and user feedback for attachment retrieval
  • New Features

    • Added specific error messaging for attachment-related issues
  • Documentation

    • Updated error messages to provide clearer user guidance when attachments cannot be found

The changes focus on improving the reliability and user experience when working with file attachments across the application.

Copy link

coderabbitai bot commented Jan 30, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request focuses on improving error handling and attachment retrieval across the application. Changes span both backend and frontend, introducing more robust checks for attachment existence and enhancing user feedback when attachments cannot be found. The modifications involve adding storage existence checks in the backend models and views, updating frontend components to handle attachment fetch failures, and adding a localization message for attachment-related errors.

Changes

File Change Summary
backend/core/models.py Enhanced get_size method to check attachment existence in storage
backend/core/views.py Added storage existence check in attachment action of EvidenceViewSet
frontend/messages/en.json Added new error message for attachment not found scenario
frontend/src/lib/components/ModelTable/EvidenceFilePreview.svelte Added couldFetch property to Attachment interface and error handling
frontend/src/routes/(app)/(third-party)/evidences/[id=uuid]/+page.svelte Updated Attachment interface and added conditional rendering for fetch failures

Sequence Diagram

sequenceDiagram
    participant Frontend
    participant Backend
    participant Storage
    
    Frontend->>Backend: Request Attachment
    Backend->>Storage: Check Attachment Existence
    alt Attachment Exists
        Storage-->>Backend: Attachment Found
        Backend-->>Frontend: Return Attachment
    else Attachment Not Found
        Storage-->>Backend: Attachment Missing
        Backend-->>Frontend: Return 404 Error
        Frontend->>Frontend: Display Error Message
    end
Loading

Poem

🐰 Attachments, oh attachments, where art thou?
Checked with care, no file shall slip now
Backend guards, frontend warns with grace
A robust dance in our digital space
Error messages bloom like spring's first flower 🌼


🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@nas-tabchiche
Copy link
Contributor

@coderabbitai full review

Copy link

coderabbitai bot commented Jan 31, 2025

✅ Actions performed

Full review triggered.

Copy link

@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

🧹 Nitpick comments (2)
backend/core/views.py (2)

3134-3134: Remove debug print statement.

The commented-out print statement should be removed as it's not needed in production code.

-        # print("==> ATTACHEMENT CALLED")

3138-3141: Remove debug print statement and fix typo.

The commented-out print statement should be removed and there's a typo in "ATTACHEMENT".

-            # print("=============\n",evidence.attachment.name,  evidence.attachment.storage.exists(evidence.attachment.name), "\n========")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d37a5c1 and 84186dd.

📒 Files selected for processing (5)
  • backend/core/models.py (1 hunks)
  • backend/core/views.py (1 hunks)
  • frontend/messages/en.json (1 hunks)
  • frontend/src/lib/components/ModelTable/EvidenceFilePreview.svelte (2 hunks)
  • frontend/src/routes/(app)/(third-party)/evidences/[id=uuid]/+page.svelte (3 hunks)
🔇 Additional comments (9)
frontend/src/lib/components/ModelTable/EvidenceFilePreview.svelte (3)

Line range hint 7-11: LGTM! Interface enhancement for better error handling.

The addition of couldFetch to the Attachment interface enables proper tracking of attachment fetch status.


19-23: LGTM! Robust fetch status check.

The fetch status check is comprehensive, verifying both:

  • HTTP response status via res.ok
  • Error message in blob content

49-50: LGTM! User-friendly error feedback.

Good addition of error message display when attachment fetch fails, using the localized message.

frontend/src/routes/(app)/(third-party)/evidences/[id=uuid]/+page.svelte (3)

19-22: LGTM! Consistent interface enhancement.

The addition of couldFetch to the Attachment interface maintains consistency with EvidenceFilePreview.svelte.


53-57: LGTM! Consistent fetch status check.

The fetch status check implementation matches EvidenceFilePreview.svelte, ensuring consistent behavior.


190-194: LGTM! Consistent error handling UI.

The error message display implementation aligns with EvidenceFilePreview.svelte, providing a consistent user experience.

backend/core/views.py (1)

3139-3141: LGTM! Robust attachment existence check.

The addition of storage.exists() check prevents the application from crashing when an attachment file is missing.

frontend/messages/en.json (1)

777-777: LGTM! Clear error message.

The added message "Error: Could not find attachment." is clear and user-friendly.

backend/core/models.py (1)

1722-1724: LGTM! Good defensive programming.

The additional check for file existence in storage is a robust solution that prevents crashes when the file is missing from the storage system.

backend/core/models.py Outdated Show resolved Hide resolved
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