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

Hide traceback when automatic annotation has failed #8636

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Nov 1, 2024

Motivation and context

Now it shows the error message when automatic annotations has failed:
image

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

Release Notes

  • New Features

    • Enhanced error handling and reporting for job statuses, improving feedback clarity for users.
    • Simplified error messages during inference status failures for a more streamlined user experience.
  • Bug Fixes

    • Improved handling of file uploads and cloud storage interactions to ensure correct file paths and storage instances.
  • Documentation

    • Updated error messaging in notifications to reflect more accurate failure contexts.
  • Chores

    • Refactored several methods for clarity and efficiency, enhancing overall maintainability.

@bsekachev bsekachev requested a review from Marishka17 as a code owner November 1, 2024 17:18
Copy link
Contributor

coderabbitai bot commented Nov 1, 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 focus on enhancing error handling and control flow across multiple files in the CVAT project. Key modifications include the introduction of more robust error reporting mechanisms, simplification of error handling logic, and updates to the structure of various methods to improve clarity and maintainability. Notable alterations involve the removal of functions, updates to existing methods, and adjustments in how error messages are generated and reported in both the backend and frontend components.

Changes

File Path Change Summary
cvat-core/src/lambda-manager.ts Enhanced error handling in LambdaManager class; nullish coalescing used for progress defaults; improved error messages in RQStatus.FAILED.
cvat-core/src/server-proxy.ts Removed filterPythonTraceback function; simplified error handling in generateError; ensured correct cookie handling in setAuthData.
cvat-ui/src/actions/models-actions.ts Simplified error dispatching in listen function; now only includes the error message without task ID and status.
cvat-ui/src/reducers/notifications-reducer.ts Updated error message for GET_INFERENCE_STATUS_FAILED to reflect automatic annotation failure.
cvat/apps/engine/views.py Improved error handling in rq_exception_handler; updated _import_annotations for better file handling; enhanced content_v2 method.
cvat/apps/lambda_manager/views.py Updated to_dict method in LambdaJob for better error reporting; modified retrieve and destroy methods in RequestViewSet for consistency.

Poem

🐰 In the code where errors play,
A little fix brightens the day.
With clearer messages, we cheer,
Robust handling, never fear!
So hop along, let’s code and sing,
For every change, a joyful spring! 🌼


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/lambda-manager.ts (1)

174-182: Consider enhancing error recovery for status retrieval failures.

While the current error handling is good, consider these improvements:

  1. Add retry logic for transient network errors
  2. Provide more specific error messages based on error type (network, server, etc.)

Example enhancement:

let retries = 3;
const fetchStatus = async (): Promise<void> => {
    try {
        const response = await serverProxy.lambda.status(requestID);
        // existing success handling
    } catch (error: unknown) {
        if (retries > 0 && isNetworkError(error)) {
            retries--;
            setTimeout(fetchStatus, 1000);
            return;
        }
        // existing error handling with specific messages
        const message = error instanceof Error ? 
            (isNetworkError(error) ? 'Network error' : error.message) :
            'Unknown error';
        onUpdate.forEach((update) => update(RQStatus.UNKNOWN, 0, message));
    }
};
cvat-ui/src/actions/models-actions.ts (1)

141-141: Improved error handling for failed automatic annotations.

The change effectively wraps the error message in a new Error object, which helps standardize error handling and aligns with the PR objective of hiding traceback information from users.

Consider adding a custom error class to better distinguish automatic annotation failures from other errors:

class AutoAnnotationError extends Error {
  constructor(message: string) {
    super(message);
    this.name = 'AutoAnnotationError';
  }
}

// Usage at line 141:
new AutoAnnotationError(message as string),

This would make it easier to:

  1. Filter and handle automatic annotation errors specifically
  2. Add additional context or metadata if needed in the future
  3. Maintain consistent error handling across the codebase
cvat-core/src/server-proxy.ts (1)

Line range hint 177-209: Consider scope of error message changes

The simplified error handling affects all server errors, not just automatic annotation failures. While this provides more direct error information, consider:

  1. Adding a sanitization layer for sensitive information in production
  2. Documenting the expected error message format for backend developers

Consider introducing an error message sanitizer that can be toggled based on the environment (development/production) to control the level of detail in error messages.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a4a989d and e83cb9a.

📒 Files selected for processing (6)
  • cvat-core/src/lambda-manager.ts (1 hunks)
  • cvat-core/src/server-proxy.ts (1 hunks)
  • cvat-ui/src/actions/models-actions.ts (1 hunks)
  • cvat-ui/src/reducers/notifications-reducer.ts (1 hunks)
  • cvat/apps/engine/views.py (1 hunks)
  • cvat/apps/lambda_manager/views.py (1 hunks)
🔇 Additional comments (10)
cvat-core/src/lambda-manager.ts (3)

152-152: LGTM: Improved progress handling with nullish coalescing.

The change from || to ?? operator is more precise for handling undefined progress values while preserving valid zero progress states.


158-164: LGTM: Enhanced error reporting with clearer messages.

The changes improve error handling by:

  • Using appropriate progress defaults (100 for finished, 0 for failed)
  • Including exception info in a user-friendly format without raw traceback

166-170: LGTM: Robust handling of unexpected states.

Good defensive programming practice with clear error messaging and appropriate progress defaults.

cvat/apps/lambda_manager/views.py (2)

626-632: LGTM! Error handling improvement aligns with PR objectives.

The changes effectively implement the PR's goal of hiding raw tracebacks by:

  1. Mapping DEFERRED status to QUEUED for consistency
  2. Using formatted exceptions from metadata instead of raw tracebacks when available for failed jobs

This improves the user experience by showing more user-friendly error messages.


630-632: Verify security implications of error messages.

While using formatted exceptions improves UX, ensure that the formatted messages in RQJobMetaField.FORMATTED_EXCEPTION don't contain sensitive information like stack traces, internal paths, or system details.

✅ Verification successful

Let me check how the exceptions are formatted by looking at the parse_exception_message function.


Let me try a different approach to find the exception formatting implementation using ripgrep.


Exception handling is secure and properly sanitized

The implementation of parse_exception_message shows that the formatted exceptions only extract user-friendly error messages from REST framework exceptions, removing any sensitive information. The function:

  • Specifically handles REST framework validation errors
  • Extracts only the error message string
  • Strips out implementation details and stack traces
  • Has a safe fallback to the original message if parsing fails
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential sensitive information in formatted exceptions
rg -g '!*.pyc' -g '!*.min.js' "FORMATTED_EXCEPTION.*=.*" -A 5

Length of output: 816


Script:

#!/bin/bash
# Find the parse_exception_message implementation
ast-grep --pattern 'def parse_exception_message($_) { $$$ }'

Length of output: 62


Script:

#!/bin/bash
# Search for parse_exception_message function definition and usage
rg -g '*.py' "def parse_exception_message" -B 2 -A 10

Length of output: 857

cvat-ui/src/reducers/notifications-reducer.ts (2)

888-888: LGTM! Error message simplified for better UX.

The simplified error message for automatic annotation failure aligns well with the PR objective to hide traceback errors from users. This change improves user experience by providing clearer, less technical feedback.


Line range hint 888-894: Verify error handling consistency.

The error handling implementation maintains the established pattern:

  1. Preserves error logging through shouldLog
  2. Retains task-specific context via task ID link
  3. Follows the standard error object structure

Consider documenting these error handling patterns in the codebase to ensure consistent implementation across the application.

✅ Verification successful

Error handling implementation follows consistent pattern across codebase

The error handling implementation in the modified code follows the established pattern used throughout the notifications reducer:

  1. All error states consistently use the same structure with message, reason, and shouldLog properties
  2. The shouldLog function is used uniformly across all error cases (70+ occurrences) to determine logging behavior
  3. Error messages maintain a consistent format, including task-specific context via task ID links where applicable
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar error handling patterns to ensure consistency
rg -U "message:.*reason:.*shouldLog:" --type ts

Length of output: 49


Script:

#!/bin/bash
# Let's try a more flexible pattern to find error handling structures
rg -U "message.*error.*shouldLog" --type ts -A 2

Length of output: 284


Script:

#!/bin/bash
# Search for notification state handling patterns
ast-grep --pattern 'state = {
  $$$
  errors: {
    $$$
  }
  $$$
}'

Length of output: 70


Script:

#!/bin/bash
# Look for error object structures
rg "errors: \{" --type ts -A 5

Length of output: 49120


Script:

#!/bin/bash
# Find shouldLog usage patterns
rg "shouldLog\(" --type ts -A 2

Length of output: 24794

cvat-core/src/server-proxy.ts (2)

Line range hint 177-209: LGTM: Error handling changes look good

The simplified error handling implementation:

  1. Successfully achieves the goal of hiding traceback
  2. Maintains proper error type differentiation
  3. Preserves the existing error handling structure

177-177: Verify error message handling for 500 errors

The change to directly use response data for 500 errors aligns with the PR objective to simplify error handling. However, we should ensure that the error messages displayed to users are still user-friendly and don't expose sensitive implementation details.

✅ Verification successful

Let me gather more information about the error handling implementation to ensure a comprehensive verification.


Based on the comprehensive analysis of the error handling implementation, I can now provide the final response:

Error handling implementation is appropriate and secure

The direct usage of error response data in ServerError is safe because:

  • The error handling is properly structured with different cases (400s, 500s)
  • Error messages are appropriately formatted and sanitized where needed (using toString() for field errors)
  • The UI layer (cvat-ui) has additional error handling logic that filters out sensitive errors (codes 0, 400, 401, 403, 404, 429, 500)
  • The error messages are consistently wrapped in ServerError class which provides a controlled interface for error information
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any existing error message formatting or sanitization
rg -g '*.ts' -g '*.tsx' 'errorData\.response\.data.*toString\(\)' -A 3

Length of output: 771


Script:

#!/bin/bash
# Check the complete error handling implementation
ast-grep --pattern 'function generateError($_) {
  $$$
}'

# Look for any other error message processing
rg -g '*.ts' -g '*.tsx' 'ServerError|Error.*message' -A 3

Length of output: 15365

cvat/apps/engine/views.py (1)

3255-3260: Error handling enhancement looks good

The rq_exception_handler function correctly formats and parses the exception message before saving it to the job metadata. This aligns with the PR objective of hiding tracebacks from users when automatic annotation fails.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 6.45161% with 29 lines in your changes missing coverage. Please review.

Project coverage is 74.30%. Comparing base (a652191) to head (b6164a0).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8636      +/-   ##
===========================================
+ Coverage    74.28%   74.30%   +0.01%     
===========================================
  Files          401      401              
  Lines        43395    43402       +7     
  Branches      3945     3945              
===========================================
+ Hits         32237    32250      +13     
+ Misses       11158    11152       -6     
Components Coverage Δ
cvat-ui 78.66% <3.70%> (+0.02%) ⬆️
cvat-server 70.58% <25.00%> (+0.01%) ⬆️

Copy link

sonarqubecloud bot commented Nov 5, 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.

2 participants