Back to all reviewers

Fail with messages

Homebrew/brew
Based on 3 comments
Shell

Functions and scripts should never fail silently. When detecting error conditions, always provide clear error messages to stderr that include context about what failed and why, then return an appropriate non-zero exit code. For user-facing commands, include guidance about correct usage when applicable.

Error Handling Shell

Reviewer Prompt

Functions and scripts should never fail silently. When detecting error conditions, always provide clear error messages to stderr that include context about what failed and why, then return an appropriate non-zero exit code. For user-facing commands, include guidance about correct usage when applicable.

Example:

url_get() {
  if [[ ${#} -eq 0 ]]; then
    echo "Error: url_get requires at least one argument (URL)" >&2
    return 1
  fi
  
  # Function implementation...
}

# Usage with error checking
eval RESULTS=( $(url_get "${URL}" param1 param2) )
if [[ ${#RESULTS[@]} -ne 2 ]]; then
  echo "Error: Failed to parse URL=${URL}!" >&2
  exit 1
fi
3
Comments Analyzed
Shell
Primary Language
Error Handling
Category

Source Discussions