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

Fixed issue: Cannot read properties of undefined (reading 'getUpdated') #8785

Merged
merged 7 commits into from
Dec 6, 2024

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Dec 6, 2024

Motivation and context

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue preventing access to the 'getUpdated' property, eliminating runtime exceptions.
  • New Features

    • Enhanced error handling in frame metadata saving and retrieval processes, improving application stability.
  • Chores

    • Updated the version of the cvat-core project from 15.3.0 to 15.3.1.

@bsekachev bsekachev requested a review from nmanovic as a code owner December 6, 2024 13:39
Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

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 changes in this pull request address a runtime error related to accessing an undefined object's property and update the version number of the cvat-core package. Additionally, modifications were made to the saveJobMeta and getFrameMeta functions within the frames.ts file to enhance promise handling and error management. The method signatures of several functions were also updated to reflect these changes, ensuring improved clarity and maintainability in the codebase.

Changes

File Path Change Summary
changelog.d/20241206_153723_sekachev.bs_fixed_issue.md Fixed issue with reading properties of an undefined object in relation to the 'getUpdated' property.
cvat-core/package.json Updated version from "15.3.0" to "15.3.1".
cvat-core/src/frames.ts Modified saveJobMeta and getFrameMeta functions for improved promise handling and error management. Updated method signatures for multiple functions.

Poem

In the code where errors lay,
A fix has come to save the day!
With promises wrapped and caches bright,
Our frames now dance in pure delight.
Version updated, all is well,
Hooray for changes, hear us yell! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 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.

Copy link
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: 0

🧹 Outside diff range and nitpick comments (3)
cvat-core/src/frames.ts (3)

563-577: Approve the fix for undefined property access

The changes properly handle the Promise chain and error cases, preventing the "Cannot read properties of undefined" error. The implementation now ensures that frameMetaCache[jobID] always contains a valid Promise, even in error scenarios.

However, consider adding a comment explaining the error handling strategy:

 frameMetaCache[jobID] = new Promise<FramesMetaData>((resolve) => {
+    // Resolve with original meta on error to maintain cache consistency
     serverProxy.frames.saveMeta('job', jobID, {

563-577: Consider improving error propagation

While the current implementation prevents the undefined error, it might mask other legitimate errors by always resolving the Promise. Consider using Promise.reject for error cases that should be handled by the caller.

 }).catch((error) => {
-    resolve(meta);
-    throw error;
+    // Reject the promise to allow proper error handling upstream
+    return Promise.reject(error);
 });

563-577: Document the caching strategy

The frame meta caching logic is complex and crucial for the system's operation. Consider adding documentation that explains:

  • The caching lifecycle
  • Error handling strategy
  • Cache invalidation rules
+/**
+ * Saves job meta data to the server and updates the cache
+ * @param meta The meta data to save
+ * @param jobID The job ID
+ * @returns A promise that resolves with the updated meta data
+ * 
+ * Cache behavior:
+ * - On success: Cache is updated with new server response
+ * - On error: Cache maintains the original meta to prevent undefined access
+ * - Cache is invalidated when the job is cleared
+ */
 async function saveJobMeta(meta: FramesMetaData, jobID: number): Promise<FramesMetaData> {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ca3d700 and fdd57ff.

📒 Files selected for processing (3)
  • changelog.d/20241206_153723_sekachev.bs_fixed_issue.md (1 hunks)
  • cvat-core/package.json (1 hunks)
  • cvat-core/src/frames.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • cvat-core/package.json
  • changelog.d/20241206_153723_sekachev.bs_fixed_issue.md
🔇 Additional comments (1)
cvat-core/src/frames.ts (1)

563-577: Verify error handling in the UI layer

The changes in error handling behavior might affect how errors are displayed to users in the UI.

✅ Verification successful

Based on the search results, I can now provide a final response regarding the error handling verification:

Error handling is properly implemented in the UI layer

The error from frames.saveMeta is already handled appropriately:

  • The error is caught in the core layer and propagated up while maintaining the previous state through resolve(meta)
  • The UI layer has a comprehensive error notification system that displays errors through notification.error()
  • Errors are displayed with proper context, descriptions, and custom CSS classes for styling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any UI components that handle errors from saveJobMeta
rg -l "saveJobMeta.*catch" --type ts

Length of output: 38


Script:

#!/bin/bash
# Let's search for UI components that might handle frame deletion or meta updates
rg -A 5 "frames\.saveMeta" --type ts

Length of output: 551


Script:

#!/bin/bash
# Let's also check for any error handling patterns in UI components related to frames
rg -A 5 "deletedFrames|frameMetaCache" --type ts

Length of output: 7245


Script:

#!/bin/bash
# Search for components that might show error notifications
ast-grep --pattern 'catch (error) { $$$ }'

Length of output: 44


Script:

#!/bin/bash
# Let's search for UI components that might handle frame-related errors
rg -A 5 "notification.*error|showError|handleError" --type ts

Length of output: 35412


Script:

#!/bin/bash
# Let's check how errors are handled in the UI layer
rg -A 5 "catch.*error.*notification" --type ts

Length of output: 1330

Copy link

sonarqubecloud bot commented Dec 6, 2024

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 61.53846% with 10 lines in your changes missing coverage. Please review.

Project coverage is 73.92%. Comparing base (ca3d700) to head (fec1187).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8785   +/-   ##
========================================
  Coverage    73.92%   73.92%           
========================================
  Files          409      409           
  Lines        43950    43958    +8     
  Branches      3985     3986    +1     
========================================
+ Hits         32488    32495    +7     
- Misses       11462    11463    +1     
Components Coverage Δ
cvat-ui 78.34% <61.53%> (+<0.01%) ⬆️
cvat-server 70.14% <ø> (ø)

@bsekachev bsekachev merged commit 12eec54 into develop Dec 6, 2024
35 checks passed
@cvat-bot cvat-bot bot mentioned this pull request Dec 9, 2024
@bsekachev bsekachev deleted the bs/fixed_issue branch December 11, 2024 08:07
archibald1418 pushed a commit that referenced this pull request Dec 18, 2024
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.

3 participants