question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crashing in runner.py due to AttributeError raised by checking None for keys

See original GitHub issue

Describe the bug I am getting a crash similar in appearance to #118 but for Terraform and not CloudFormation.

Scanning file: /some_directory/some-file.tf
full_file_path is /other_directory/some_directory/some-file.tf
Traceback (most recent call last):
  File "/my_path/bin/checkov", line 5, in <module>
    run()
  File "/my_path/lib/python3.7/site-packages/checkov/main.py", line 108, in run
    guidelines=guidelines, bc_integration=bc_integration)
  File "/my_path/lib/python3.7/site-packages/checkov/common/runners/runner_registry.py", line 35, in run
    runner_filter=self.runner_filter, collect_skip_comments=collect_skip_comments)
  File "/my_path/lib/python3.7/site-packages/checkov/terraform/runner.py", line 78, in run
    self.check_tf_definition(report, root_folder, runner_filter, collect_skip_comments)
  File "/my_path/lib/python3.7/site-packages/checkov/terraform/runner.py", line 100, in check_tf_definition
    scanned_file, runner_filter, abs_referrer)
  File "/my_path/lib/python3.7/site-packages/checkov/terraform/runner.py", line 104, in run_all_blocks
    for block_type in definition.keys():
AttributeError: 'NoneType' object has no attribute 'keys'

To Reproduce edit: See https://github.com/bridgecrewio/checkov/issues/941#issuecomment-790803047

That’s the thing 😢 It’s real hard to reproduce, if I run checkov just on the file that it crashes on, things work fine! If I run it on just the last 10 files it scans before crashing, things work fine. For testing this, I’d recommend you simply run this on a big repo with a lot of output from find . -type f -name "*.tf" and then turn all the files into individual --file arguments, like my cool checkov wrapper package does. e.g. checkov --check CKV_AWS_88 --file fileA.tf --fileB.tf (to save time, I just limited this to 1 check, but it could be any other check id)

Steps to reproduce the behavior:

  1. Run cli command checkov --check CKV_AWS_88 --file fileA.tf --fileB.tf on a ton of --file arguments. Pray it triggers the bug.
  2. See error

Expected behavior No crashing.

Desktop (please complete the following information):

  • OS: OS X
  • Checkov Version: the latest as of today: 1.0.825

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
robedencommented, Mar 3, 2021

That might make sense given how it loops over things? Hard to say for sure without being able to reproduce, but I’m pretty sure I have a change that will avoid the problem.

1reaction
robedencommented, Mar 3, 2021

Ok. Normality restored. 🤪

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crashing in runner.py due to AttributeError raised by checking None ...
Describe the bug. I am getting a crash similar in appearance to #118 but for Terraform and not CloudFormation. Scanning file: /some_directory/some-file.tf ...
Read more >
checkov hanging after crash of lexer scanning terraform #2717
When running checkov against terraform formatted in a particular way a crash occurs in a child process and the checkov process hangs forever....
Read more >
Python unittest - opposite of assertRaises? - Stack Overflow
The solution proposed by user9876 is conceptually flawed: if you test for the non-raising of say ValueError , but ValueError is instead raised,...
Read more >
Changelog — Python 3.11.1 documentation
compile_command() when checking for incomplete input. Previously it emitted warnings and raised a SyntaxError. Now it always returns None for incomplete input ...
Read more >
Writing Avocado Tests — Avocado 61.0 documentation
We are going to write an Avocado test in Python and we are going to inherit ... so when the machine or python...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found