Skip to content

Commit 67ef57c

Browse files
committed
check_keywords_txt: Improve error/warning messages
1 parent 63acb9e commit 67ef57c

File tree

2 files changed

+111
-66
lines changed

2 files changed

+111
-66
lines changed

arduino-ci-script.sh

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,14 +2045,14 @@ function check_keywords_txt() {
20452045

20462046
# Check whether folder exists
20472047
if [[ ! -d "$normalizedKeywordsTxtSearchPath" ]]; then
2048-
echo "ERROR: Specified folder: $normalizedKeywordsTxtSearchPath doesn't exist."
2048+
echo "ERROR: ${normalizedKeywordsTxtSearchPath}: Folder doesn't exist."
20492049
return $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_FOLDER_DOESNT_EXIST_EXIT_STATUS
20502050
fi
20512051

20522052
while read -r normalizedKeywordsTxtPath; do
20532053
# Check for misspelled keywords.txt filename
20542054
if [[ "$(find "$normalizedKeywordsTxtPath" -type f -iname 'keyword.txt')" || "$(find "$normalizedKeywordsTxtPath" -type f -iregex '.*/keywords?\.text')" || "$(find "$normalizedKeywordsTxtPath" -type f -iregex '.*/keywords?\.txt\.txt')" ]]; then
2055-
echo "ERROR: $normalizedKeywordsTxtPath contains an incorrectly spelled keywords.txt file."
2055+
echo "ERROR: ${normalizedKeywordsTxtPath}: Incorrectly spelled keywords.txt file. It must be spelled exactly \"keywords.txt\"."
20562056
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_MISSPELLED_FILENAME_EXIT_STATUS)
20572057
fi
20582058

@@ -2067,7 +2067,7 @@ function check_keywords_txt() {
20672067
if [[ "${foundKeywordsTxtPath: -12}" == 'keywords.txt' ]]; then
20682068
keywordsTxtFound=true
20692069
else
2070-
echo "ERROR: $foundKeywordsTxtPath has incorrect filename case, which causes it to not be recognized on a filename case-sensitive OS such as Linux. It must be exactly keywords.txt"
2070+
echo "ERROR: ${foundKeywordsTxtPath}: Incorrect filename case, which causes it to not be recognized on a filename case-sensitive OS such as Linux. It must be exactly \"keywords.txt\"."
20712071
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_INCORRECT_FILENAME_CASE_EXIT_STATUS)
20722072
fi
20732073
done <<<"$(find "$normalizedKeywordsTxtPath" -maxdepth 1 -type f -iname 'keywords.txt')"
@@ -2095,15 +2095,16 @@ function check_keywords_txt() {
20952095
local BOMcorruptedCommentRegex='^.[[:space:]]*#'
20962096
local BOMcorruptedBlankLineRegex='^.[[:space:]]*$'
20972097
if [[ "$keywordsTxtLine" =~ $BOMcorruptedCommentRegex ]] || [[ "$keywordsTxtLine" =~ $BOMcorruptedBlankLineRegex ]]; then
2098-
echo "WARNING: BOM found. In this case it does not cause an issue but it's recommended to use UTF-8 encoding for keywords.txt."
2098+
echo "WARNING: ${normalizedKeywordsTxtPath}/keywords.txt: BOM found. In this case it does not cause an issue but it's recommended to use UTF-8 encoding for keywords.txt."
20992099
continue
21002100
fi
21012101
fi
21022102

21032103
local spacesSeparatorRegex='^[[:space:]]*[^[:space:]]+ +[^[:space:]]+'
21042104
# Check for invalid separator
21052105
if [[ "$keywordsTxtLine" =~ $spacesSeparatorRegex ]]; then
2106-
echo "ERROR: $normalizedKeywordsTxtPath (${keywordsTxtLine}) uses space(s) as a field separator. It must be a true tab."
2106+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Space(s) used as a field separator. Fields must be separated by a single true tab."
2107+
echo -e "\t$keywordsTxtLine"
21072108
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_INVALID_FIELD_SEPARATOR_EXIT_STATUS)
21082109
# The rest of the checks will be borked by messed up field separators so continue to the next line
21092110
continue
@@ -2112,7 +2113,8 @@ function check_keywords_txt() {
21122113
# Check for multiple tabs used as separator where this causes unintended results
21132114
local consequentialMultipleSeparatorRegex='^[[:space:]]*[^[:space:]]+[[:space:]]*'$'\t''+[[:space:]]*'$'\t''+[[:space:]]*((KEYWORD1)|(LITERAL1))'
21142115
if [[ "$keywordsTxtLine" =~ $consequentialMultipleSeparatorRegex ]]; then
2115-
echo "ERROR: $normalizedKeywordsTxtPath (${keywordsTxtLine}) uses multiple tabs as field separator. It must be a single tab. This causes the default keyword highlighting (as used by KEYWORD2, KEYWORD3, LITERAL2) to be used rather than the intended highlighting."
2116+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Multiple tabs used as field separator. It must be a single tab. This causes the default keyword highlighting (as used by KEYWORD2, KEYWORD3, LITERAL2) to be used rather than the intended highlighting."
2117+
echo -e "\t$keywordsTxtLine"
21162118
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_MULTIPLE_TABS_EXIT_STATUS)
21172119
# The rest of the checks will be borked by messed up field separators so continue to the next line
21182120
continue
@@ -2121,7 +2123,8 @@ function check_keywords_txt() {
21212123
# Check for multiple tabs used as separator where this causes no unintended results
21222124
local inconsequentialMultipleSeparatorRegex='^[[:space:]]*[^[:space:]]+[[:space:]]*'$'\t''+[[:space:]]*'$'\t''+[[:space:]]*((KEYWORD2)|(KEYWORD3)|(LITERAL2))'
21232125
if [[ "$keywordsTxtLine" =~ $inconsequentialMultipleSeparatorRegex ]]; then
2124-
echo "ERROR: $normalizedKeywordsTxtPath (${keywordsTxtLine}) uses multiple tabs as field separator. It must be a single tab. This causes the default keyword highlighting (as used by KEYWORD2, KEYWORD3, LITERAL2). In this case that doesn't cause the keywords to be incorrectly colored as expected but it's recommended to fully comply with the Arduino library specification."
2126+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Multiple tabs used as field separator. It must be a single tab. This causes the default keyword highlighting (as used by KEYWORD2, KEYWORD3, LITERAL2). In this case that doesn't cause the keywords to be colored other than intended but it's recommended to fully comply with the Arduino library specification."
2127+
echo -e "\t$keywordsTxtLine"
21252128
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_INCONSEQUENTIAL_MULTIPLE_TABS_EXIT_STATUS)
21262129
# The rest of the checks will be borked by messed up field separators so continue to the next line
21272130
continue
@@ -2130,7 +2133,8 @@ function check_keywords_txt() {
21302133
# Check for invalid line
21312134
local invalidLineRegex='^[[:space:]]*[^[:space:]]+[[:space:]]*$'
21322135
if [[ "$keywordsTxtLine" =~ $invalidLineRegex ]]; then
2133-
echo "ERROR: $normalizedKeywordsTxtPath has an invalid line: ${keywordsTxtLine}. If this was intended as a comment, it should use the correct # syntax."
2136+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Invalid line. If this was intended as a comment, it should use the correct # syntax."
2137+
echo -e "\t$keywordsTxtLine"
21342138
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_INVALID_LINE_EXIT_STATUS)
21352139
# The rest of the checks are pointless so continue to the next line of keywords.txt
21362140
continue
@@ -2176,12 +2180,13 @@ function check_keywords_txt() {
21762180
allowedKeywordCharactersRegex='^[a-zA-Z0-9_]+$'
21772181
# Check for corruption of KEYWORD field caused by UTF-8 BOM file encoding
21782182
if grep --quiet $'\xEF\xBB\xBF' <<<"$keyword"; then
2179-
echo "ERROR: $normalizedKeywordsTxtPath uses UTF-8 BOM file encoding, which has corrupted the first keyword definition. Please change the file encoding to standard UTF-8."
2183+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: UTF-8 BOM file encoding has corrupted the first keyword definition. Please change the file encoding to standard UTF-8."
21802184
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_BOM_CORRUPTED_KEYWORD_EXIT_STATUS)
21812185
elif ! [[ "$keyword" =~ $allowedKeywordCharactersRegex ]]; then
21822186
# Check for invalid characters in KEYWORD
21832187
# The Arduino IDE does recognize keywords that start with a number, even though these are not valid identifiers.
2184-
echo "ERROR: Keyword $keyword in $normalizedKeywordsTxtPath contains invalid character(s), which causes it to not be recognized by the Arduino IDE. Keywords may only contain the characters a-z, A-Z, 0-9, and _."
2188+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Keyword: $keyword contains invalid character(s), which causes it to not be recognized by the Arduino IDE. Keywords may only contain the characters a-z, A-Z, 0-9, and _."
2189+
echo -e "\t$keywordsTxtLine"
21852190
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_INVALID_KEYWORD_EXIT_STATUS)
21862191
fi
21872192

@@ -2195,15 +2200,18 @@ function check_keywords_txt() {
21952200
# Check if the issue doesn't cause any change from the intended highlighting
21962201
local inconsequentialTokentypeRegex='((KEYWORD2)|(KEYWORD3)|(LITERAL2))'
21972202
if [[ "$keywordTokentypeWithoutLeadingSpace" =~ $inconsequentialTokentypeRegex ]]; then
2198-
echo "ERROR: $normalizedKeywordsTxtPath (${keywordsTxtLine}) has leading space on the KEYWORD_TOKENTYPE field, which causes it to not be recognized, so the default keyword highlighting is used. In this case that doesn't cause the keywords to be incorrectly colored as expected but it's recommended to fully comply with the Arduino library specification."
2203+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Leading space on the KEYWORD_TOKENTYPE field causes it to not be recognized, so the default keyword highlighting is used. In this case that doesn't cause the keywords to be colored other than intended but it's recommended to fully comply with the Arduino library specification."
2204+
echo -e "\t$keywordsTxtLine"
21992205
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_INCONSEQUENTIAL_LEADING_SPACE_ON_KEYWORD_TOKENTYPE_EXIT_STATUS)
22002206
else
2201-
echo "ERROR: $normalizedKeywordsTxtPath (${keywordsTxtLine}) has leading space on the KEYWORD_TOKENTYPE field, which causes it to not be recognized, so the default keyword highlighting is used."
2207+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Leading space on the KEYWORD_TOKENTYPE field causes it to not be recognized, so the default keyword highlighting is used."
2208+
echo -e "\t$keywordsTxtLine"
22022209
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_LEADING_SPACE_ON_KEYWORD_TOKENTYPE_EXIT_STATUS)
22032210
fi
22042211
elif ! [[ "$keywordTokentypeWithoutLeadingSpace" == "" && "$rsyntaxtextareaTokentype" =~ $validRsyntaxtextareaTokentypeRegex ]]; then
22052212
# It's reasonable to leave KEYWORD_TOKENTYPE blank if RSYNTAXTEXTAREA_TOKENTYPE is defined and valid. This will not be compatible with 1.6.4 and older but that's really no big deal.
2206-
echo "ERROR: $normalizedKeywordsTxtPath (${keywordsTxtLine}) uses invalid KEYWORD_TOKENTYPE: ${keywordTokentype}, which causes the default keyword highlighting to be used. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keyword_tokentype"
2213+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Invalid KEYWORD_TOKENTYPE: $keywordTokentype causes the default keyword highlighting to be used. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keyword_tokentype"
2214+
echo -e "\t$keywordsTxtLine"
22072215
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_INVALID_KEYWORD_TOKENTYPE_EXIT_STATUS)
22082216
fi
22092217
fi
@@ -2216,7 +2224,8 @@ function check_keywords_txt() {
22162224
else
22172225
install_ide_version "$NEWEST_INSTALLED_IDE_VERSION"
22182226
if [[ ! $(find "${ARDUINO_CI_SCRIPT_APPLICATION_FOLDER}/${ARDUINO_CI_SCRIPT_IDE_INSTALLATION_FOLDER}/reference/www.arduino.cc/en/Reference/" -type f -name "${referenceLink}.html") ]]; then
2219-
echo "ERROR: $normalizedKeywordsTxtPath (${keywordsTxtLine}) uses a REFERENCE_LINK value: $referenceLink that is not a valid Arduino Language Reference page. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#reference_link"
2227+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: REFERENCE_LINK value: $referenceLink is not a valid Arduino Language Reference page. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#reference_link"
2228+
echo -e "\t$keywordsTxtLine"
22202229
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_INVALID_REFERENCE_LINK_EXIT_STATUS)
22212230
fi
22222231
fi
@@ -2228,10 +2237,12 @@ function check_keywords_txt() {
22282237
# Check if it's invalid only because of leading space
22292238
local rsyntaxtextareaTokentypeWithoutLeadingSpace="${rsyntaxtextareaTokentype#"${rsyntaxtextareaTokentype%%[![:space:]]*}"}"
22302239
if [[ "$rsyntaxtextareaTokentypeWithoutLeadingSpace" =~ $validRsyntaxtextareaTokentypeRegex ]]; then
2231-
echo "ERROR: $normalizedKeywordsTxtPath (${keywordsTxtLine}) has leading space on the RSYNTAXTEXTAREA_TOKENTYPE field, which causes it to not be recognized, so the default keyword highlighting is used."
2240+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Leading space on the RSYNTAXTEXTAREA_TOKENTYPE field causes it to not be recognized, so the default keyword highlighting is used."
2241+
echo -e "\t$keywordsTxtLine"
22322242
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_LEADING_SPACE_ON_RSYNTAXTEXTAREA_TOKENTYPE_EXIT_STATUS)
22332243
else
2234-
echo "ERROR: $normalizedKeywordsTxtPath (${keywordsTxtLine}) uses invalid RSYNTAXTEXTAREA_TOKENTYPE: ${rsyntaxtextareaTokentype}, which causes the default keyword highlighting to be used. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#rsyntaxtextarea_tokentype"
2244+
echo "ERROR: ${normalizedKeywordsTxtPath}/keywords.txt: Invalid RSYNTAXTEXTAREA_TOKENTYPE: $rsyntaxtextareaTokentype causes the default keyword highlighting to be used. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#rsyntaxtextarea_tokentype"
2245+
echo -e "\t$keywordsTxtLine"
22352246
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_KEYWORDS_TXT_INVALID_RSYNTAXTEXTAREA_TOKENTYPE_EXIT_STATUS)
22362247
fi
22372248
fi

0 commit comments

Comments
 (0)