check-spelling / check-spelling

Spelling checker action to check spelling in repositories / pull requests / commits
https://check-spelling.dev
MIT License
264 stars 32 forks source link

Error: jq: error (at /tmp/tmp.cGzaIQjE6g.json:4): Cannot index string with string "user" #50

Open ricardo-dematos opened 1 year ago

ricardo-dematos commented 1 year ago

With release 0.0.21 I'm getting Error: jq: error (at /tmp/tmp.cGzaIQjE6g.json:4): Cannot index string with string "user".

There's just an annotation in job summary, because the step outcome is success.

Here's the step log :

Run check-spelling/check-spelling@v0.0.21
  with:
    event_aliases: {"workflow_call":"push"}
    config: .github/actions/check-spelling
    only_check_changed_files: 0
    post_comment: 0
    extra_dictionaries: cspell:en_GB/src/wordsEnGb.txt cspell:en_GB/src/additional_words.txt cspell:en_US/src/en_US.txt cspell:en_US/src/additional_words.txt cspell:en_US/src/contractions-and-possessives.txt cspell:en_US/src/hyphenated-words.txt cspell:pt_PT/Portuguese-European.txt cspell:software-terms/src/software-terms.txt cspell:software-terms/src/software-tools.txt cspell:software-terms/src/network-protocols.txt cspell:software-terms/src/network-os.txt cspell:cryptocurrencies/cryptocurrencies.txt cspell:public-licenses/src/generated/public-licenses.txt cspell:public-licenses/src/additional-licenses.txt cspell:lorem-ipsum/dictionary.txt cspell:mnemonics/src/mnemonics.txt cspell:companies/src/companies.txt cspell:aws/aws.txt cspell:docker/src/docker-words.txt cspell:bash/bash-words.txt cspell:fullstack/fullstack.txt cspell:django/django.txt cspell:django/requirements.txt cspell:node/additional_words.txt cspell:node/node.txt cspell:node/src/node-old.txt cspell:npm/npm.txt cspell:python/src/python/python.txt cspell:python/src/python/python-lib.txt cspell:python/src/common/extra.txt cspell:python/src/additional_words.txt cspell:typescript/typescript.txt cspell:html/html.txt cspell:html-symbol-entities/entities.txt cspell:css/css.txt cspell:fonts/fonts.txt cspell:filetypes/filetypes.txt
    GITHUB_TOKEN: ***
    experimental_path: .
    dictionary_url: https://raw.githubusercontent.com/check-spelling/check-spelling/dictionary-$DICTIONARY_VERSION/dict.txt
    dictionary_version: 20200211
    experimental_apply_changes_via_bot: 0
    experimental_parallel_jobs: 2
    dictionary_source_prefixes: {"cspell": "https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20220816/dictionaries/"}
    check_extra_dictionaries: cspell:ada/ada.txt cspell:aws/aws.txt cspell:bash/bash-words.txt cspell:clojure/src/clojure.txt cspell:companies/src/companies.txt cspell:cpp/src/compiler-clang-attributes.txt cspell:cpp/src/compiler-gcc.txt cspell:cpp/src/compiler-msvc.txt cspell:cpp/src/cpp.txt cspell:cpp/src/ecosystem.txt cspell:cpp/src/lang-jargon.txt cspell:cpp/src/lang-keywords.txt cspell:cpp/src/people.txt cspell:cpp/src/stdlib-c.txt cspell:cpp/src/stdlib-cerrno.txt cspell:cpp/src/stdlib-cmath.txt cspell:cpp/src/stdlib-cpp.txt cspell:cpp/src/template-strings.txt cspell:cryptocurrencies/cryptocurrencies.txt cspell:csharp/csharp.txt cspell:css/css.txt cspell:dart/src/dart.txt cspell:django/django.txt cspell:django/requirements.txt cspell:docker/src/docker-words.txt cspell:dotnet/dotnet.txt cspell:elixir/elixir.txt cspell:filetypes/filetypes.txt cspell:fonts/fonts.txt cspell:fullstack/fullstack.txt cspell:golang/go.txt cspell:haskell/haskell.txt cspell:html-symbol-entities/entities.txt cspell:html/html.txt cspell:java/java.txt cspell:latex/latex.txt cspell:latex/samples/sample-words.txt cspell:lorem-ipsum/dictionary.txt cspell:lua/lua.txt cspell:mnemonics/src/mnemonics.txt cspell:monkeyc/src/monkeyc_keywords.txt cspell:node/additional_words.txt cspell:node/node.txt cspell:node/src/node-old.txt cspell:npm/npm.txt cspell:php/php.txt cspell:powershell/powershell.txt cspell:public-licenses/src/additional-licenses.txt cspell:public-licenses/src/generated/public-licenses.txt cspell:python/src/additional_words.txt cspell:python/src/common/extra.txt cspell:python/src/python/python-lib.txt cspell:python/src/python/python.txt cspell:r/src/r.txt cspell:ruby/ruby.txt cspell:rust/rust.txt cspell:scala/scala.txt cspell:software-terms/src/network-os.txt cspell:software-terms/src/network-protocols.txt cspell:software-terms/src/software-terms.txt cspell:software-terms/src/software-tools.txt cspell:sql/src/sql.txt cspell:sql/src/tsql.txt cspell:swift/src/swift.txt cspell:typescript/typescript.txt cspell:win32/src/win32.txt
    extra_dictionary_limit: 5
    shortest_word: 3
    largest_file: 1048576
    unknown_word_limit: 5
    warnings: bad-regex,binary-file,deprecated-feature,large-file,limited-references,no-newline-at-eof,noisy-file,non-alpha-in-dictionary,unexpected-line-ending,whitespace-in-dictionary,minified-file,unsupported-configuration
    notices: candidate-pattern
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.16/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.16/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.16/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.16/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.16/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.16/x64/lib
Run stdbuf -i0 -o0 -e0 "/home/runner/work/_actions/check-spelling/check-spelling/v0.0.21/unknown-words.sh"
  stdbuf -i0 -o0 -e0 "/home/runner/work/_actions/check-spelling/check-spelling/v0.0.21/unknown-words.sh"
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.16/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.16/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.16/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.16/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.16/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.16/x64/lib
    INPUTS: {
    "event_aliases": "{\"workflow_call\":\"push\"}",
    "config": ".github/actions/check-spelling",
    "only_check_changed_files": "0",
    "post_comment": "0",
    "extra_dictionaries": "cspell:en_GB/src/wordsEnGb.txt cspell:en_GB/src/additional_words.txt cspell:en_US/src/en_US.txt cspell:en_US/src/additional_words.txt cspell:en_US/src/contractions-and-possessives.txt cspell:en_US/src/hyphenated-words.txt cspell:pt_PT/Portuguese-European.txt cspell:software-terms/src/software-terms.txt cspell:software-terms/src/software-tools.txt cspell:software-terms/src/network-protocols.txt cspell:software-terms/src/network-os.txt cspell:cryptocurrencies/cryptocurrencies.txt cspell:public-licenses/src/generated/public-licenses.txt cspell:public-licenses/src/additional-licenses.txt cspell:lorem-ipsum/dictionary.txt cspell:mnemonics/src/mnemonics.txt cspell:companies/src/companies.txt cspell:aws/aws.txt cspell:docker/src/docker-words.txt cspell:bash/bash-words.txt cspell:fullstack/fullstack.txt cspell:django/django.txt cspell:django/requirements.txt cspell:node/additional_words.txt cspell:node/node.txt cspell:node/src/node-old.txt cspell:npm/npm.txt cspell:python/src/python/python.txt cspell:python/src/python/python-lib.txt cspell:python/src/common/extra.txt cspell:python/src/additional_words.txt cspell:typescript/typescript.txt cspell:html/html.txt cspell:html-symbol-entities/entities.txt cspell:css/css.txt cspell:fonts/fonts.txt cspell:filetypes/filetypes.txt",
    "GITHUB_TOKEN": "***",
    "bucket": "",
    "project": "",
    "experimental_path": ".",
    "dictionary_url": "https://raw.githubusercontent.com/check-spelling/check-spelling/dictionary-$DICTIONARY_VERSION/dict.txt",
    "dictionary_version": "20200211",
    "debug": "",
    "experimental_apply_changes_via_bot": "0",
    "experimental_parallel_jobs": "2",
    "capture_output_unknown_words": "",
    "capture_output_stale_words": "",
    "capture_output_skipped_files": "",
    "dictionary_source_prefixes": "{\"cspell\": \"https://raw.githubusercontent.com/check-spelling/cspell-dicts/v20220816/dictionaries/\"}",
    "check_extra_dictionaries": "cspell:ada/ada.txt cspell:aws/aws.txt cspell:bash/bash-words.txt cspell:clojure/src/clojure.txt cspell:companies/src/companies.txt cspell:cpp/src/compiler-clang-attributes.txt cspell:cpp/src/compiler-gcc.txt cspell:cpp/src/compiler-msvc.txt cspell:cpp/src/cpp.txt cspell:cpp/src/ecosystem.txt cspell:cpp/src/lang-jargon.txt cspell:cpp/src/lang-keywords.txt cspell:cpp/src/people.txt cspell:cpp/src/stdlib-c.txt cspell:cpp/src/stdlib-cerrno.txt cspell:cpp/src/stdlib-cmath.txt cspell:cpp/src/stdlib-cpp.txt cspell:cpp/src/template-strings.txt cspell:cryptocurrencies/cryptocurrencies.txt cspell:csharp/csharp.txt cspell:css/css.txt cspell:dart/src/dart.txt cspell:django/django.txt cspell:django/requirements.txt cspell:docker/src/docker-words.txt cspell:dotnet/dotnet.txt cspell:elixir/elixir.txt cspell:filetypes/filetypes.txt cspell:fonts/fonts.txt cspell:fullstack/fullstack.txt cspell:golang/go.txt cspell:haskell/haskell.txt cspell:html-symbol-entities/entities.txt cspell:html/html.txt cspell:java/java.txt cspell:latex/latex.txt cspell:latex/samples/sample-words.txt cspell:lorem-ipsum/dictionary.txt cspell:lua/lua.txt cspell:mnemonics/src/mnemonics.txt cspell:monkeyc/src/monkeyc_keywords.txt cspell:node/additional_words.txt cspell:node/node.txt cspell:node/src/node-old.txt cspell:npm/npm.txt cspell:php/php.txt cspell:powershell/powershell.txt cspell:public-licenses/src/additional-licenses.txt cspell:public-licenses/src/generated/public-licenses.txt cspell:python/src/additional_words.txt cspell:python/src/common/extra.txt cspell:python/src/python/python-lib.txt cspell:python/src/python/python.txt cspell:r/src/r.txt cspell:ruby/ruby.txt cspell:rust/rust.txt cspell:scala/scala.txt cspell:software-terms/src/network-os.txt cspell:software-terms/src/network-protocols.txt cspell:software-terms/src/software-terms.txt cspell:software-terms/src/software-tools.txt cspell:sql/src/sql.txt cspell:sql/src/tsql.txt cspell:swift/src/swift.txt cspell:typescript/typescript.txt cspell:win32/src/win32.txt",
    "extra_dictionary_limit": "5",
    "shortest_word": "3",
    "longest_word": "",
    "experimental_commit_note": "",
    "suppress_push_for_open_pull_request": "",
    "report_title_suffix": "",
    "custom_task": "",
    "internal_state_directory": "",
    "check_file_names": "",
    "check_commit_messages": "",
    "anonymize_secpoll_source": "",
    "ignore_security_advisory": "",
    "largest_file": "1048576",
    "unknown_word_limit": "5",
    "warnings": "bad-regex,binary-file,deprecated-feature,large-file,limited-references,no-newline-at-eof,noisy-file,non-alpha-in-dictionary,unexpected-line-ending,whitespace-in-dictionary,minified-file,unsupported-configuration",
    "notices": "candidate-pattern",
    "quit_without_error": "",
    "spell_check_this": "",
    "ssh_key": "",
    "checkout": "",
    "task": "",
    "disable_checks": "",
    "alternate_engine": "",
    "alternate_engine_key": "",
    "use_sarif": "",
    "use_magic_file": "",
    "caller_container": ""
  }
    DEBUG: 
    spellchecker: /home/runner/work/_actions/check-spelling/check-spelling/v0.0.21
    GH_ACTION_REPOSITORY: check-spelling/check-spelling
    GH_ACTION_REF: v0.0.21
Found ok status for version 0.0.21: 'OK'
Retrieving expect from .github/actions/check-spelling/expect/expect.txt
Retrieving excludes from .github/actions/check-spelling/excludes/excludes.txt
Downloaded https://raw.githubusercontent.com/check-spelling/check-spelling/dictionary-20200211/dict.txt (to /home/runner/work/_actions/check-spelling/check-spelling/v0.0.21/words)
(...Extra dictionaries...)
(...Check extra dictionaries...)
Retrieving allow from .github/actions/check-spelling/allow/allow.txt
Retrieving reject from .github/actions/check-spelling/reject/reject.txt
Retrieving line_forbidden from .github/actions/check-spelling/line_forbidden.patterns
Retrieving patterns from .github/actions/check-spelling/patterns/patterns.txt
Retrieving advice from .github/actions/check-spelling/advice.md
Checking spelling...
(...Spell check files...)
Checking 133 files
(...Spell check...)
Warning: backend/valiengine/parser/helpers/alt_grammar.txt:1:1 ... 1, Warning - Skipping `backend/valiengine/parser/helpers/alt_grammar.txt` because average line width (3996) exceeds the threshold (1000). (minified-file)
(...Compare expect with new output...)
(...New output...)
(...No misspellings...)
From https://github.com/valispace/valiengine
 * branch            HEAD       -> FETCH_HEAD

# @check-spelling-bot Report
See the [:open_file_folder: files](351/files/) view or the [:scroll:action log](https://github.com/valispace/valiengine/actions/runs/4376378607/jobs/7658401343#step:5:1)  for details.

No new words with misspellings found

There are currently 122 expected items.

<details><summary>Previously acknowledged words that are now absent
</summary>adamkdean addopts asgiref brpart corsheaders direnv einfo EXPRUNIT flightduration inlinevar ipynb libxmlsec modelist mypackage norecursedirs numprocesses prereleasemetadata prereleasetype prun pypackages regexes sast sonarqube sonarsource styfle svn testpaths typecheck typevar UNITTOEXPR updateonbuild vectorize vectorized viewset xdist xunit 
:arrow_right:
</details>

<details><summary>Some files were automatically ignored</summary>

These sample patterns would exclude them:

^\Qbackend/valiengine/parser/helpers/alt_grammar.txt\E$

You should consider adding them to:

.github/actions/check-spelling/excludes/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use `patterns.txt` to exclude portions, add items to the dictionary (e.g. by adding them to `allow.txt`), or fix typos.
</details>

<details><summary>Warnings (1)</summary>

See the [:open_file_folder: files](351/files/) view or the [:scroll:action log](https://github.com/valispace/valiengine/actions/runs/4376378607/jobs/7658401343#step:5:1) for details.

[:information_source: Warnings](https://github.com/check-spelling/check-spelling/wiki/Event-descriptions) | Count
-|-
[:information_source: minified-file](https://github.com/check-spelling/check-spelling/wiki/Event-descriptions#minified-file) | 1

See [:information_source: Event descriptions](https://github.com/check-spelling/check-spelling/wiki/Event-descriptions) for more information.

</details>
Error: jq: error (at /tmp/tmp.cGzaIQjE6g.json:4): Cannot index string with string "user"

Screenshot (26)

Screenshot (27)

jsoref commented 1 year ago

Not sure offhand.

It's possible it's this: https://github.com/check-spelling/check-spelling/blob/d7cd2973c513e84354f9d6cf50a6417a628a78ce/unknown-words.sh#L222

Could you set debug: 1? https://github.com/check-spelling/check-spelling/blob/d7cd2973c513e84354f9d6cf50a6417a628a78ce/action.yml#L34-L36

ricardo-dematos commented 1 year ago

I'm sorry @jsoref , but my permissions to directly commit to a repo were revoked and since the team doesn't consider this a priority, I cannot afford to create a pull request to do your test... 😞

jsoref commented 1 year ago

Hmm. Sorry to hear that. I'd be curious to know if you can reproduce in a fork of their repository with actions enabled. Or if the repository is something I can see, maybe a pointer and I can try to tinker with it.

Either way, thanks for reporting.

ricardo-dematos commented 1 year ago

Hmm. Sorry to hear that. I'd be curious to know if you can reproduce in a fork of their repository with actions enabled. Or if the repository is something I can see, maybe a pointer and I can try to tinker with it.

It's commercial software, so almost all repo's are private and non forkable.


Personally, I consider 2 types of typos:

The latter one reveals someone that types fast and doesn't review what it writes or someone on a tight schedule. Either way, if it didn't pay attention to what it was written, how confident can another one be in that code? Are the typos the only errors?

jsoref commented 1 month ago

OK. After spending a lot of time today thinking about this problem, I have a guess about what's happening...

Getting the right error from jq

For my reference, here's how one generally speaking gets the error in this issue:

(input=$(mktemp); (echo '{'; echo '"one": "hi",'; echo '"two": "three"'; echo '}') > $input; jq '.one.hi // empty' $input; grep -n . $input)
jq: error (at /var/folders/r3/n29fz25x72x191fdv6mhhr3m0000gp/T/tmp.xacwS27O9i:4): Cannot index string with string "hi"
1:{
2:"one": "hi",
3:"two": "three"
4:}

The number 4 really does end up being the line count of the file.

(input=$(mktemp); (echo '[';echo '{'; echo '"one": "hi",'; echo '"a": "b",';echo '"two": "three"'; echo '}'; echo ']') > $input; jq '.[0].one.hi // empty' $
input; grep -n . $input)
jq: error (at /var/folders/r3/n29fz25x72x191fdv6mhhr3m0000gp/T/tmp.ThKPqJ4ZpX:7): Cannot index string with string "hi"
1:[
2:{
3:"one": "hi",
4:"a": "b",
5:"two": "three"
6:}
7:]

Getting an object of the right shape from GitHub

Warning: while the number 4 is key, I don't think anyone running v0.0.21 today would see 4, instead, I think they'd see 5.

That's because, I believe this is actually a permissions error (the fact that this was a private repository hinted at that).

Here's a random ticket that shows what permission errors used to look like:

{
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest/collaborators/collaborators#add-a-repository-collaborator"
}

Reviewing the code

git blame v0.0.21 -- unknown-words.sh|grep -n . |perl -pe 's/ unknown-words\.sh\s*\(.*?\)//'| grep -C3 '\.user'

Sorting blocks from least likely to hardest to immediately rule out...

.issue.user.login

669:3ed5d5f59a 
670:91d4beb7be   trigger_comment_url="$(jq -r '.url // empty' "$comment")"
671:91d4beb7be   sender_login="$(jq -r '.sender.login // empty' "$GITHUB_EVENT_PATH")"
672:91d4beb7be   issue_user_login="$(jq -r '.issue.user.login // empty' "$GITHUB_EVENT_PATH")"
673:91d4beb7be   pull_request_head_info="$(mktemp_json)"
674:eb9549b783   jq .head "$pull_request_info" > "$pull_request_head_info"
675:91d4beb7be   pull_request_sha="$(jq -r '.sha // empty' "$pull_request_head_info")"

.user.id in track_comment

2352:af30e6ff6b track_comment() {
2353:91d4beb7be   HTML_COMMENT_URL="$(jq -r '.html_url // empty' "$response")"
2354:91d4beb7be   echo "Comment posted to ${HTML_COMMENT_URL:-"$COMMENT_URL"}"
2355:4b237d4692   comment_author_id="$(jq -r '.user.id // empty' "$response")"
2356:4b237d4692   posted_comment_node_id="$(jq -r '.node_id // empty' "$response")"
2357:af30e6ff6b }
2358:af30e6ff6b 

.user.login

751:91d4beb7be     comment "$comment_url" > "$comment" ||
752:5579450a28       confused_comment "$trigger_comment_url" "Failed to retrieve $b$comment_url$b."
753:5579450a28 
754:91d4beb7be     bot_comment_author=$(jq -r '.user.login // empty' "$comment")
755:91d4beb7be     bot_comment_node_id=$(jq -r '.node_id // empty' "$comment")
756:91d4beb7be     bot_comment_url=$(jq -r '.issue_url // .comment.url' "$comment")
757:5579450a28     github_actions_bot="github-actions[bot]"

.user.id in jq_comment_query

219:4b237d4692   #   from that element, we only want the node_id
220:4b237d4692   # we want the last element
221:4b237d4692   #   if there's no element, we want the empty string (not 'null')
222:4b237d4692   jq_comment_query='[ .[] | select(. | (.user.id=='"${comment_author_id:-0}"') and (.node_id != "'"$posted_comment_node_id"'") and (.body | test ("'"$comment_search_re"'") ) ) | .node_id ] | .[-1] // empty'
223:4b237d4692 
224:4b237d4692   get_page() {
225:4b237d4692     url="$1"

This is fancier, specifically, it's expecting an array of objects.

But, what if the returned item is instead an object? Specifically that error object?

curl -q -s https://api.github.com/repos/check-spelling-sandbox/no-such-repository/pulls|jq '[ .[] | select(. | (.user.id=='2'))]' 
jq: error (at <stdin>:5): Cannot index string with string "user"

So, this is approximately the right shape of an error. The line number is wrong because GitHub added a status field a while ago, but here's what the api sent:

curl -q -s https://api.github.com/repos/check-spelling-sandbox/no-such-repository/pulls
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/pulls/pulls#list-pull-requests",
  "status": "404"
}

Reproducing the problem

Unfortunately, I can't get this to happen. I've tried using v0.0.21 with various permissions. (I'm pretty sure I tried when this was opened too.)

I wonder if it could happen if I didn't use the default GITHUB_TOKEN...

The other exciting edge about this ticket is:

    event_aliases: {"workflow_call":"push"}

I still haven't played with workflow_call much. It's by far one of the fancier GitHub features I've basically never used.

At some point, I'm going to have to try setting up a workflow_call flow and seeing how check-spelling works there.