Skip to content

Commit

Permalink
chore: improve error handling for GitHub search query
Browse files Browse the repository at this point in the history
  • Loading branch information
LangLangBart committed Sep 3, 2024
1 parent 84dc7a6 commit de6ddeb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion gh-find-code
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ gh_query() {
# processing these patterns later, split on \x1f, which is equivalent to the \u001F.
# https://condor.depaul.edu/sjost/lsp121/documents/ascii-npr.htm
# https://datatracker.ietf.org/doc/html/rfc20#section-4.1
patterns: ([.value.text_matches[] | .. | .text? | select(type=="string") | sub("\n\\\s*$"; "")] as $patterns_array |
# Remove all newline characters from any pattern
patterns: ([.value.text_matches[] | .. | .text? | select(type=="string") | gsub("\n"; "")] as $patterns_array |
if $patterns_array == [] then "__NoPatternFound__" else $patterns_array | unique | join("\u001F") end)
# Separating the fields with the Record Separator (RS). @tsv is not suitable because it
Expand All @@ -535,6 +536,15 @@ gh_query() {
if grep --quiet --ignore-case "API rate limit exceeded" "$store_gh_search_error"; then
show_api_limits >>"$store_gh_search_error"
fi
if grep --quiet --ignore-case "unable to parse query" "$store_gh_search_error"; then
cat <<EOF >>"$store_gh_search_error"
ADVICE:
1. If you are using an escape sequences inside double quotes, escape them. For example:
- Instead of: "Tab \t"
- Use: "Tab \\\t"
EOF
fi
if [[ ! -s $store_gh_search_error ]]; then
echo "Unknown reason: The query failed, but no error text was written." >>"$store_gh_search_error"
fi
Expand Down

0 comments on commit de6ddeb

Please sign in to comment.