Back to all reviewers

Log exceptions with context

prowler-cloud/prowler
Based on 2 comments
Python

When handling exceptions in your code, ensure they are properly logged with sufficient context to aid debugging. For critical exceptions, use Sentry to track them alongside regular logging. For handled exceptions, include both the object being processed and the exception details in your log message.

Logging Python

Reviewer Prompt

When handling exceptions in your code, ensure they are properly logged with sufficient context to aid debugging. For critical exceptions, use Sentry to track them alongside regular logging. For handled exceptions, include both the object being processed and the exception details in your log message.

Example:

try:
    result = process_item(item)
except Exception as exc:
    # For critical exceptions, capture in Sentry
    sentry_sdk.capture_exception(exc)
    
    # Always log with context information
    logger.warning(f"Failed to process '{item}': {exc}")
    
    # Then handle the exception appropriately
    # Don't silently continue without logging

Choose the appropriate log level based on severity - use error for application failures and warning for handled exceptions. Proper exception logging improves troubleshooting capabilities and helps identify recurring issues in production.

2
Comments Analyzed
Python
Primary Language
Logging
Category

Source Discussions