We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Malformed resource causes crash
**Describe the bug**
A malformed resource like this causes an exception that kills off all subsequent checks:
```terraform
resource "aws_instance" {
  ami = "amiid"
  instance_type = "t3.micro"
}
```

Example error:
```
Traceback (most recent call last):
  File "/Users/robeden/git/third-party/checkov/checkov/common/checks/base_check.py", line 62, in run
    raise e
  File "/Users/robeden/git/third-party/checkov/checkov/common/checks/base_check.py", line 42, in run
    check_result['result'] = self.scan_entity_conf(entity_configuration, entity_type)
  File "/Users/robeden/git/third-party/checkov/checkov/terraform/checks/resource/base_resource_check.py", line 16, in scan_entity_conf
    self.handle_dynamic_values(conf)
  File "/Users/robeden/git/third-party/checkov/checkov/terraform/checks/resource/base_resource_check.py", line 38, in handle_dynamic_values
    for dynamic_element in conf.get("dynamic", []):
AttributeError: 'list' object has no attribute 'get'
```

**Expected behavior**
The bad data should be skipped before being passed to checks.

Long term: it would be good to catch exceptions thrown by checks and report that something didn't work properly with the check.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `checkov/terraform/tag_providers/__init__.py`
Content:
```
1 import checkov.terraform.tag_providers.aws
2 import checkov.terraform.tag_providers.azure
3 import checkov.terraform.tag_providers.gcp
4 
5 provider_tag_mapping = {
6     'aws': aws.get_resource_tags,
7     'azure': azure.get_resource_tags,
8     'gcp': gcp.get_resource_tags
9 }
10 
11 
12 def get_resource_tags(resource_type, entity_config):
13     if '_' not in resource_type:
14         return None  # probably not a resource block
15     provider = resource_type[:resource_type.index('_')]
16     provider_tag_function = provider_tag_mapping.get(provider)
17     if provider_tag_function:
18         return provider_tag_function(entity_config)
19     else:
20         return None
21
```

Path: `checkov/common/checks/base_check_registry.py`
Content:
```
1 import fnmatch
2 import importlib
3 import logging
4 import os
5 import sys
6 from abc import abstractmethod
7 from itertools import chain
8 from typing import Generator, Tuple
9 
10 from checkov.common.checks.base_check import BaseCheck
11 
12 from collections import defaultdict
13 
14 from checkov.runner_filter import RunnerFilter
15 
16 
17 class BaseCheckRegistry(object):
18     # NOTE: Needs to be static to because external check loading may be triggered by a registry to which
19     #       checks aren't registered. (This happens with Serverless, for example.)
20     __loading_external_checks = False
21 
22     def __init__(self):
23         self.logger = logging.getLogger(__name__)
24         # IMPLEMENTATION NOTE: Checks is used to directly access checks based on an specific entity
25         self.checks = defaultdict(list)
26         # IMPLEMENTATION NOTE: When using a wildcard, every pattern needs to be checked. To reduce the
27         #                      number of checks checks with the same pattern are grouped, which is the
28         #                      reason to use a dict for this too.
29         self.wildcard_checks = defaultdict(list)
30         self.check_id_allowlist = None
31 
32     def register(self, check):
33         # IMPLEMENTATION NOTE: Checks are registered when the script is loaded
34         #                      (see BaseResourceCheck.__init__() for the various frameworks). The only
35         #                      difficultly with this process is that external checks need to be specially
36         #                      identified for filter handling. That's why you'll see stateful setting of
37         #                      RunnerFilters during load_external_checks.
38         #                      Built-in checks are registered immediately at script start, before
39         #                      external checks.
40         if BaseCheckRegistry.__loading_external_checks:
41             RunnerFilter.notify_external_check(check.id)
42 
43         for entity in check.supported_entities:
44             checks = self.wildcard_checks if self._is_wildcard(entity) else self.checks
45             checks[entity].append(check)
46 
47     @staticmethod
48     def _is_wildcard(entity):
49         return ('*' in entity
50                 or '?' in entity
51                 or ('[' in entity and ']' in entity))
52 
53     def get_check_by_id(self, check_id):
54         return next(
55             filter(
56                 lambda c: c.id == check_id,
57                 chain(*self.checks.values(), *self.wildcard_checks.values())
58             ), None)
59 
60     def all_checks(self) -> Generator[Tuple[str, BaseCheck], None, None]:
61         for entity, checks in self.checks.items():
62             for check in checks:
63                 yield entity, check
64         for entity, checks in self.wildcard_checks.items():
65             for check in checks:
66                 yield entity, check
67 
68     @property
69     def contains_wildcard(self) -> bool:
70         return bool(self.wildcard_checks)
71 
72     def get_checks(self, entity):
73         if not self.wildcard_checks:
74             # Optimisation: When no wildcards are used, we can use the list in self.checks
75             return self.checks.get(entity) or []
76         else:
77             res = self.checks[entity].copy() if entity in self.checks.keys() else []
78             # check wildcards
79             for pattern, checks in self.wildcard_checks.items():
80                 if fnmatch.fnmatchcase(entity, pattern):
81                     res += checks
82             return res
83 
84     def set_checks_allowlist(self, runner_filter):
85         if runner_filter.checks:
86             self.check_id_allowlist = runner_filter.checks
87 
88     @abstractmethod
89     def extract_entity_details(self, entity):
90         raise NotImplementedError()
91 
92     def scan(self, scanned_file, entity, skipped_checks, runner_filter):
93 
94         (entity_type, entity_name, entity_configuration) = self.extract_entity_details(entity)
95 
96         results = {}
97         checks = self.get_checks(entity_type)
98         for check in checks:
99             skip_info = {}
100             if skipped_checks:
101                 if check.id in [x['id'] for x in skipped_checks]:
102                     skip_info = [x for x in skipped_checks if x['id'] == check.id][0]
103 
104             if runner_filter.should_run_check(check.id):
105                 result = self.run_check(check, entity_configuration, entity_name, entity_type, scanned_file, skip_info)
106                 results[check] = result
107         return results
108 
109     def run_check(self, check, entity_configuration, entity_name, entity_type, scanned_file, skip_info, tags=None):
110         self.logger.debug("Running check: {} on file {}".format(check.name, scanned_file))
111         result = check.run(scanned_file=scanned_file, entity_configuration=entity_configuration,
112                            entity_name=entity_name, entity_type=entity_type, skip_info=skip_info)
113         return result
114 
115     @staticmethod
116     def _directory_has_init_py(directory):
117         """ Check if a given directory contains a file named __init__.py.
118 
119         __init__.py is needed to ensure the directory is a Python module, thus
120         can be imported.
121         """
122         if os.path.exists("{}/__init__.py".format(directory)):
123             return True
124         return False
125 
126     @staticmethod
127     def _file_can_be_imported(entry):
128         """ Verify if a directory entry is a non-magic Python file."""
129         if entry.is_file() and not entry.name.startswith('__') and entry.name.endswith('.py'):
130             return True
131         return False
132 
133     def load_external_checks(self, directory, runner_filter):
134         """ Browse a directory looking for .py files to import.
135 
136         Log an error when the directory does not contains an __init__.py or
137         when a .py file has syntax error
138         """
139         directory = os.path.expanduser(directory)
140         self.logger.debug("Loading external checks from {}".format(directory))
141         sys.path.insert(1, directory)
142 
143         with os.scandir(directory) as directory_content:
144             if not self._directory_has_init_py(directory):
145                 self.logger.info("No __init__.py found in {}. Cannot load any check here.".format(directory))
146             else:
147                 for entry in directory_content:
148                     if self._file_can_be_imported(entry):
149                         check_name = entry.name.replace('.py', '')
150 
151                         # Filter is set while loading external checks so the filter can be informed
152                         # of the checks, which need to be handled specially.
153                         try:
154                             BaseCheckRegistry.__loading_external_checks = True
155                             self.logger.debug("Importing external check '{}'".format(check_name))
156                             importlib.import_module(check_name)
157                         except SyntaxError as e:
158                             self.logger.error(
159                                 "Cannot load external check '{check_name}' from {check_full_path} : {error_message} ("
160                                 "{error_line}:{error_column}) "
161                                     .format(
162                                     check_name=check_name,
163                                     check_full_path=e.args[1][0],
164                                     error_message=e.args[0],
165                                     error_line=e.args[1][1],
166                                     error_column=e.args[1][2]
167                                 )
168                             )
169                         finally:
170                             BaseCheckRegistry.__loading_external_checks = False
171
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/checkov/common/checks/base_check_registry.py b/checkov/common/checks/base_check_registry.py
--- a/checkov/common/checks/base_check_registry.py
+++ b/checkov/common/checks/base_check_registry.py
@@ -94,6 +94,10 @@
         (entity_type, entity_name, entity_configuration) = self.extract_entity_details(entity)
 
         results = {}
+
+        if not isinstance(entity_configuration, dict):
+            return results
+
         checks = self.get_checks(entity_type)
         for check in checks:
             skip_info = {}
diff --git a/checkov/terraform/tag_providers/__init__.py b/checkov/terraform/tag_providers/__init__.py
--- a/checkov/terraform/tag_providers/__init__.py
+++ b/checkov/terraform/tag_providers/__init__.py
@@ -10,6 +10,9 @@
 
 
 def get_resource_tags(resource_type, entity_config):
+    if not isinstance(entity_config, dict):
+        return None
+
     if '_' not in resource_type:
         return None  # probably not a resource block
     provider = resource_type[:resource_type.index('_')]

{"golden_diff": "diff --git a/checkov/common/checks/base_check_registry.py b/checkov/common/checks/base_check_registry.py\n--- a/checkov/common/checks/base_check_registry.py\n+++ b/checkov/common/checks/base_check_registry.py\n@@ -94,6 +94,10 @@\n         (entity_type, entity_name, entity_configuration) = self.extract_entity_details(entity)\n \n         results = {}\n+\n+        if not isinstance(entity_configuration, dict):\n+            return results\n+\n         checks = self.get_checks(entity_type)\n         for check in checks:\n             skip_info = {}\ndiff --git a/checkov/terraform/tag_providers/__init__.py b/checkov/terraform/tag_providers/__init__.py\n--- a/checkov/terraform/tag_providers/__init__.py\n+++ b/checkov/terraform/tag_providers/__init__.py\n@@ -10,6 +10,9 @@\n \n \n def get_resource_tags(resource_type, entity_config):\n+    if not isinstance(entity_config, dict):\n+        return None\n+\n     if '_' not in resource_type:\n         return None  # probably not a resource block\n     provider = resource_type[:resource_type.index('_')]\n", "issue": "Malformed resource causes crash\n**Describe the bug**\r\nA malformed resource like this causes an exception that kills off all subsequent checks:\r\n```terraform\r\nresource \"aws_instance\" {\r\n  ami = \"amiid\"\r\n  instance_type = \"t3.micro\"\r\n}\r\n```\r\n\r\nExample error:\r\n```\r\nTraceback (most recent call last):\r\n  File \"/Users/robeden/git/third-party/checkov/checkov/common/checks/base_check.py\", line 62, in run\r\n    raise e\r\n  File \"/Users/robeden/git/third-party/checkov/checkov/common/checks/base_check.py\", line 42, in run\r\n    check_result['result'] = self.scan_entity_conf(entity_configuration, entity_type)\r\n  File \"/Users/robeden/git/third-party/checkov/checkov/terraform/checks/resource/base_resource_check.py\", line 16, in scan_entity_conf\r\n    self.handle_dynamic_values(conf)\r\n  File \"/Users/robeden/git/third-party/checkov/checkov/terraform/checks/resource/base_resource_check.py\", line 38, in handle_dynamic_values\r\n    for dynamic_element in conf.get(\"dynamic\", []):\r\nAttributeError: 'list' object has no attribute 'get'\r\n```\r\n\r\n**Expected behavior**\r\nThe bad data should be skipped before being passed to checks.\r\n\r\nLong term: it would be good to catch exceptions thrown by checks and report that something didn't work properly with the check.\n", "before_files": [{"content": "import checkov.terraform.tag_providers.aws\nimport checkov.terraform.tag_providers.azure\nimport checkov.terraform.tag_providers.gcp\n\nprovider_tag_mapping = {\n    'aws': aws.get_resource_tags,\n    'azure': azure.get_resource_tags,\n    'gcp': gcp.get_resource_tags\n}\n\n\ndef get_resource_tags(resource_type, entity_config):\n    if '_' not in resource_type:\n        return None  # probably not a resource block\n    provider = resource_type[:resource_type.index('_')]\n    provider_tag_function = provider_tag_mapping.get(provider)\n    if provider_tag_function:\n        return provider_tag_function(entity_config)\n    else:\n        return None\n", "path": "checkov/terraform/tag_providers/__init__.py"}, {"content": "import fnmatch\nimport importlib\nimport logging\nimport os\nimport sys\nfrom abc import abstractmethod\nfrom itertools import chain\nfrom typing import Generator, Tuple\n\nfrom checkov.common.checks.base_check import BaseCheck\n\nfrom collections import defaultdict\n\nfrom checkov.runner_filter import RunnerFilter\n\n\nclass BaseCheckRegistry(object):\n    # NOTE: Needs to be static to because external check loading may be triggered by a registry to which\n    #       checks aren't registered. (This happens with Serverless, for example.)\n    __loading_external_checks = False\n\n    def __init__(self):\n        self.logger = logging.getLogger(__name__)\n        # IMPLEMENTATION NOTE: Checks is used to directly access checks based on an specific entity\n        self.checks = defaultdict(list)\n        # IMPLEMENTATION NOTE: When using a wildcard, every pattern needs to be checked. To reduce the\n        #                      number of checks checks with the same pattern are grouped, which is the\n        #                      reason to use a dict for this too.\n        self.wildcard_checks = defaultdict(list)\n        self.check_id_allowlist = None\n\n    def register(self, check):\n        # IMPLEMENTATION NOTE: Checks are registered when the script is loaded\n        #                      (see BaseResourceCheck.__init__() for the various frameworks). The only\n        #                      difficultly with this process is that external checks need to be specially\n        #                      identified for filter handling. That's why you'll see stateful setting of\n        #                      RunnerFilters during load_external_checks.\n        #                      Built-in checks are registered immediately at script start, before\n        #                      external checks.\n        if BaseCheckRegistry.__loading_external_checks:\n            RunnerFilter.notify_external_check(check.id)\n\n        for entity in check.supported_entities:\n            checks = self.wildcard_checks if self._is_wildcard(entity) else self.checks\n            checks[entity].append(check)\n\n    @staticmethod\n    def _is_wildcard(entity):\n        return ('*' in entity\n                or '?' in entity\n                or ('[' in entity and ']' in entity))\n\n    def get_check_by_id(self, check_id):\n        return next(\n            filter(\n                lambda c: c.id == check_id,\n                chain(*self.checks.values(), *self.wildcard_checks.values())\n            ), None)\n\n    def all_checks(self) -> Generator[Tuple[str, BaseCheck], None, None]:\n        for entity, checks in self.checks.items():\n            for check in checks:\n                yield entity, check\n        for entity, checks in self.wildcard_checks.items():\n            for check in checks:\n                yield entity, check\n\n    @property\n    def contains_wildcard(self) -> bool:\n        return bool(self.wildcard_checks)\n\n    def get_checks(self, entity):\n        if not self.wildcard_checks:\n            # Optimisation: When no wildcards are used, we can use the list in self.checks\n            return self.checks.get(entity) or []\n        else:\n            res = self.checks[entity].copy() if entity in self.checks.keys() else []\n            # check wildcards\n            for pattern, checks in self.wildcard_checks.items():\n                if fnmatch.fnmatchcase(entity, pattern):\n                    res += checks\n            return res\n\n    def set_checks_allowlist(self, runner_filter):\n        if runner_filter.checks:\n            self.check_id_allowlist = runner_filter.checks\n\n    @abstractmethod\n    def extract_entity_details(self, entity):\n        raise NotImplementedError()\n\n    def scan(self, scanned_file, entity, skipped_checks, runner_filter):\n\n        (entity_type, entity_name, entity_configuration) = self.extract_entity_details(entity)\n\n        results = {}\n        checks = self.get_checks(entity_type)\n        for check in checks:\n            skip_info = {}\n            if skipped_checks:\n                if check.id in [x['id'] for x in skipped_checks]:\n                    skip_info = [x for x in skipped_checks if x['id'] == check.id][0]\n\n            if runner_filter.should_run_check(check.id):\n                result = self.run_check(check, entity_configuration, entity_name, entity_type, scanned_file, skip_info)\n                results[check] = result\n        return results\n\n    def run_check(self, check, entity_configuration, entity_name, entity_type, scanned_file, skip_info, tags=None):\n        self.logger.debug(\"Running check: {} on file {}\".format(check.name, scanned_file))\n        result = check.run(scanned_file=scanned_file, entity_configuration=entity_configuration,\n                           entity_name=entity_name, entity_type=entity_type, skip_info=skip_info)\n        return result\n\n    @staticmethod\n    def _directory_has_init_py(directory):\n        \"\"\" Check if a given directory contains a file named __init__.py.\n\n        __init__.py is needed to ensure the directory is a Python module, thus\n        can be imported.\n        \"\"\"\n        if os.path.exists(\"{}/__init__.py\".format(directory)):\n            return True\n        return False\n\n    @staticmethod\n    def _file_can_be_imported(entry):\n        \"\"\" Verify if a directory entry is a non-magic Python file.\"\"\"\n        if entry.is_file() and not entry.name.startswith('__') and entry.name.endswith('.py'):\n            return True\n        return False\n\n    def load_external_checks(self, directory, runner_filter):\n        \"\"\" Browse a directory looking for .py files to import.\n\n        Log an error when the directory does not contains an __init__.py or\n        when a .py file has syntax error\n        \"\"\"\n        directory = os.path.expanduser(directory)\n        self.logger.debug(\"Loading external checks from {}\".format(directory))\n        sys.path.insert(1, directory)\n\n        with os.scandir(directory) as directory_content:\n            if not self._directory_has_init_py(directory):\n                self.logger.info(\"No __init__.py found in {}. Cannot load any check here.\".format(directory))\n            else:\n                for entry in directory_content:\n                    if self._file_can_be_imported(entry):\n                        check_name = entry.name.replace('.py', '')\n\n                        # Filter is set while loading external checks so the filter can be informed\n                        # of the checks, which need to be handled specially.\n                        try:\n                            BaseCheckRegistry.__loading_external_checks = True\n                            self.logger.debug(\"Importing external check '{}'\".format(check_name))\n                            importlib.import_module(check_name)\n                        except SyntaxError as e:\n                            self.logger.error(\n                                \"Cannot load external check '{check_name}' from {check_full_path} : {error_message} (\"\n                                \"{error_line}:{error_column}) \"\n                                    .format(\n                                    check_name=check_name,\n                                    check_full_path=e.args[1][0],\n                                    error_message=e.args[0],\n                                    error_line=e.args[1][1],\n                                    error_column=e.args[1][2]\n                                )\n                            )\n                        finally:\n                            BaseCheckRegistry.__loading_external_checks = False\n", "path": "checkov/common/checks/base_check_registry.py"}], "after_files": [{"content": "import checkov.terraform.tag_providers.aws\nimport checkov.terraform.tag_providers.azure\nimport checkov.terraform.tag_providers.gcp\n\nprovider_tag_mapping = {\n    'aws': aws.get_resource_tags,\n    'azure': azure.get_resource_tags,\n    'gcp': gcp.get_resource_tags\n}\n\n\ndef get_resource_tags(resource_type, entity_config):\n    if not isinstance(entity_config, dict):\n        return None\n\n    if '_' not in resource_type:\n        return None  # probably not a resource block\n    provider = resource_type[:resource_type.index('_')]\n    provider_tag_function = provider_tag_mapping.get(provider)\n    if provider_tag_function:\n        return provider_tag_function(entity_config)\n    else:\n        return None\n", "path": "checkov/terraform/tag_providers/__init__.py"}, {"content": "import fnmatch\nimport importlib\nimport logging\nimport os\nimport sys\nfrom abc import abstractmethod\nfrom itertools import chain\nfrom typing import Generator, Tuple\n\nfrom checkov.common.checks.base_check import BaseCheck\n\nfrom collections import defaultdict\n\nfrom checkov.runner_filter import RunnerFilter\n\n\nclass BaseCheckRegistry(object):\n    # NOTE: Needs to be static to because external check loading may be triggered by a registry to which\n    #       checks aren't registered. (This happens with Serverless, for example.)\n    __loading_external_checks = False\n\n    def __init__(self):\n        self.logger = logging.getLogger(__name__)\n        # IMPLEMENTATION NOTE: Checks is used to directly access checks based on an specific entity\n        self.checks = defaultdict(list)\n        # IMPLEMENTATION NOTE: When using a wildcard, every pattern needs to be checked. To reduce the\n        #                      number of checks checks with the same pattern are grouped, which is the\n        #                      reason to use a dict for this too.\n        self.wildcard_checks = defaultdict(list)\n        self.check_id_allowlist = None\n\n    def register(self, check):\n        # IMPLEMENTATION NOTE: Checks are registered when the script is loaded\n        #                      (see BaseResourceCheck.__init__() for the various frameworks). The only\n        #                      difficultly with this process is that external checks need to be specially\n        #                      identified for filter handling. That's why you'll see stateful setting of\n        #                      RunnerFilters during load_external_checks.\n        #                      Built-in checks are registered immediately at script start, before\n        #                      external checks.\n        if BaseCheckRegistry.__loading_external_checks:\n            RunnerFilter.notify_external_check(check.id)\n\n        for entity in check.supported_entities:\n            checks = self.wildcard_checks if self._is_wildcard(entity) else self.checks\n            checks[entity].append(check)\n\n    @staticmethod\n    def _is_wildcard(entity):\n        return ('*' in entity\n                or '?' in entity\n                or ('[' in entity and ']' in entity))\n\n    def get_check_by_id(self, check_id):\n        return next(\n            filter(\n                lambda c: c.id == check_id,\n                chain(*self.checks.values(), *self.wildcard_checks.values())\n            ), None)\n\n    def all_checks(self) -> Generator[Tuple[str, BaseCheck], None, None]:\n        for entity, checks in self.checks.items():\n            for check in checks:\n                yield entity, check\n        for entity, checks in self.wildcard_checks.items():\n            for check in checks:\n                yield entity, check\n\n    @property\n    def contains_wildcard(self) -> bool:\n        return bool(self.wildcard_checks)\n\n    def get_checks(self, entity):\n        if not self.wildcard_checks:\n            # Optimisation: When no wildcards are used, we can use the list in self.checks\n            return self.checks.get(entity) or []\n        else:\n            res = self.checks[entity].copy() if entity in self.checks.keys() else []\n            # check wildcards\n            for pattern, checks in self.wildcard_checks.items():\n                if fnmatch.fnmatchcase(entity, pattern):\n                    res += checks\n            return res\n\n    def set_checks_allowlist(self, runner_filter):\n        if runner_filter.checks:\n            self.check_id_allowlist = runner_filter.checks\n\n    @abstractmethod\n    def extract_entity_details(self, entity):\n        raise NotImplementedError()\n\n    def scan(self, scanned_file, entity, skipped_checks, runner_filter):\n\n        (entity_type, entity_name, entity_configuration) = self.extract_entity_details(entity)\n\n        results = {}\n\n        if not isinstance(entity_configuration, dict):\n            return results\n\n        checks = self.get_checks(entity_type)\n        for check in checks:\n            skip_info = {}\n            if skipped_checks:\n                if check.id in [x['id'] for x in skipped_checks]:\n                    skip_info = [x for x in skipped_checks if x['id'] == check.id][0]\n\n            if runner_filter.should_run_check(check.id):\n                result = self.run_check(check, entity_configuration, entity_name, entity_type, scanned_file, skip_info)\n                results[check] = result\n        return results\n\n    def run_check(self, check, entity_configuration, entity_name, entity_type, scanned_file, skip_info, tags=None):\n        self.logger.debug(\"Running check: {} on file {}\".format(check.name, scanned_file))\n        result = check.run(scanned_file=scanned_file, entity_configuration=entity_configuration,\n                           entity_name=entity_name, entity_type=entity_type, skip_info=skip_info)\n        return result\n\n    @staticmethod\n    def _directory_has_init_py(directory):\n        \"\"\" Check if a given directory contains a file named __init__.py.\n\n        __init__.py is needed to ensure the directory is a Python module, thus\n        can be imported.\n        \"\"\"\n        if os.path.exists(\"{}/__init__.py\".format(directory)):\n            return True\n        return False\n\n    @staticmethod\n    def _file_can_be_imported(entry):\n        \"\"\" Verify if a directory entry is a non-magic Python file.\"\"\"\n        if entry.is_file() and not entry.name.startswith('__') and entry.name.endswith('.py'):\n            return True\n        return False\n\n    def load_external_checks(self, directory, runner_filter):\n        \"\"\" Browse a directory looking for .py files to import.\n\n        Log an error when the directory does not contains an __init__.py or\n        when a .py file has syntax error\n        \"\"\"\n        directory = os.path.expanduser(directory)\n        self.logger.debug(\"Loading external checks from {}\".format(directory))\n        sys.path.insert(1, directory)\n\n        with os.scandir(directory) as directory_content:\n            if not self._directory_has_init_py(directory):\n                self.logger.info(\"No __init__.py found in {}. Cannot load any check here.\".format(directory))\n            else:\n                for entry in directory_content:\n                    if self._file_can_be_imported(entry):\n                        check_name = entry.name.replace('.py', '')\n\n                        # Filter is set while loading external checks so the filter can be informed\n                        # of the checks, which need to be handled specially.\n                        try:\n                            BaseCheckRegistry.__loading_external_checks = True\n                            self.logger.debug(\"Importing external check '{}'\".format(check_name))\n                            importlib.import_module(check_name)\n                        except SyntaxError as e:\n                            self.logger.error(\n                                \"Cannot load external check '{check_name}' from {check_full_path} : {error_message} (\"\n                                \"{error_line}:{error_column}) \"\n                                    .format(\n                                    check_name=check_name,\n                                    check_full_path=e.args[1][0],\n                                    error_message=e.args[0],\n                                    error_line=e.args[1][1],\n                                    error_column=e.args[1][2]\n                                )\n                            )\n                        finally:\n                            BaseCheckRegistry.__loading_external_checks = False\n", "path": "checkov/common/checks/base_check_registry.py"}]}