github.com/jmrodri/operator-sdk@v0.5.0/hack/check_error_log_msg_format.sh (about) 1 #!/bin/bash 2 3 set -o nounset 4 set -o pipefail 5 6 source "hack/lib/test_lib.sh" 7 8 echo "Checking format of error and log messages..." 9 allfiles=$(listFiles) 10 log_case_output=$(grep -PRn '(Error\((.*[Ee]rr|nil), |^(?!.*fmt).+\.Error(f)?\(|Fatal(f)?\(|Info(f)?\(|Warn(f)?\()"[[:lower:]]' $allfiles | sort -u) 11 if [ -n "${log_case_output}" ]; then 12 echo -e "Log messages do not begin with upper case:\n${log_case_output}" 13 fi 14 err_case_output=$(grep -ERn '(errors\.New|fmt\.Errorf)\("[[:upper:]]' $allfiles | sort -u) 15 if [ -n "${err_case_output}" ]; then 16 echo -e "Error messages do not begin with lower case:\n${err_case_output}" 17 fi 18 err_punct_output=$(grep -ERn '(errors\.New|fmt\.Errorf)\(".*\."' $allfiles | sort -u) 19 if [ -n "${err_punct_output}" ]; then 20 echo -e "Error messages should not have ending punctuation:\n${err_punct_output}" 21 fi 22 23 if [[ -n "$log_case_output" || -n "$err_case_output" || -n "$err_punct_output" ]]; then 24 exit 255 25 fi