Back to all reviewers

Environment-specific error handling

prettier/prettier
Based on 3 comments
JavaScript

Separate development-time assertions from production error handling based on the runtime environment. Development assertions should be used to catch programming errors and validate internal assumptions during development, while production code should focus on graceful error handling with meaningful user-facing messages.

Error Handling JavaScript

Reviewer Prompt

Separate development-time assertions from production error handling based on the runtime environment. Development assertions should be used to catch programming errors and validate internal assumptions during development, while production code should focus on graceful error handling with meaningful user-facing messages.

Use environment checks to conditionally enable development assertions:

const assertComment = process.env.NODE_ENV === "production" 
  ? noop 
  : function(comment, text) {
      if (!isLineComment(comment) && !isBlockComment(comment)) {
        throw new TypeError(`Unknown comment type: "${comment.type}".`);
      }
    };

// In production, provide simple validation with clear messages
if (!isLineComment(comment) && !isBlockComment(comment)) {
  throw new TypeError(`Unknown comment type: "${comment.type}".`);
}

This approach allows comprehensive debugging during development while maintaining clean, user-friendly error handling in production. Configure your build system to remove development-only assertions rather than replacing them with verbose conditional checks that add unnecessary complexity to the codebase.

3
Comments Analyzed
JavaScript
Primary Language
Error Handling
Category

Source Discussions