Back to all reviewers

Include contextual error information

discourse/discourse
Based on 3 comments
Ruby

Error messages should include relevant contextual information such as IDs, file paths, job identifiers, and other debugging details to make troubleshooting easier. Generic error messages make it difficult to identify the specific instance or operation that failed, especially in systems processing multiple items concurrently.

Error Handling Ruby

Reviewer Prompt

Error messages should include relevant contextual information such as IDs, file paths, job identifiers, and other debugging details to make troubleshooting easier. Generic error messages make it difficult to identify the specific instance or operation that failed, especially in systems processing multiple items concurrently.

When logging errors, include:

  • Entity IDs (upload_id, user_id, job_id, etc.)
  • File paths or URLs being processed
  • Operation context or step information
  • Request IDs when available

Example of improved error logging:

# Poor: Generic error message
Rails.logger.error("Failed to handle video conversion completion")

# Good: Contextual error message  
Rails.logger.error("Failed to handle video conversion completion for upload ID #{upload.id} and job ID #{args[:job_id]}")

# Poor: Missing context in model errors
Rails.logger.error("Failed to create optimized video: #{optimized_video.errors.full_messages.join(", ")}")

# Good: Include relevant entity context
Rails.logger.error("Failed to create optimized video for upload ID #{upload.id}: #{optimized_video.errors.full_messages.join(", ")}")

This practice significantly reduces debugging time and helps identify patterns in failures across different environments and deployments.

3
Comments Analyzed
Ruby
Primary Language
Error Handling
Category

Source Discussions