Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix None access exception #344

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions vint/linting/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from vint.linting.linter import Linter
from vint.linting.env import build_environment
from vint.linting.config.config_container import ConfigContainer
from vint.linting.config.config_container import ConfigContainer, ConfigEmptyEntryException
from vint.linting.config.config_cmdargs_source import ConfigCmdargsSource
from vint.linting.config.config_default_source import ConfigDefaultSource
from vint.linting.config.config_global_source import ConfigGlobalSource
Expand Down Expand Up @@ -34,7 +34,11 @@ def start_cli():

_adjust_log_level(env)

config_dict = _build_config_dict(env)
try:
config_dict = _build_config_dict(env)
except ConfigEmptyEntryException as e:
sys.stderr.write("[error] " + str(e) + "\n")
sys.exit(1)
violations = _lint_all(env, config_dict)

parser = _build_arg_parser()
Expand Down
26 changes: 21 additions & 5 deletions vint/linting/config/config_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@
from vint.linting.config.config_source import ConfigSource


def merge_dict_deeply(posterior, prior):
class ConfigEmptyEntryException(BaseException):
def __init__(self, path):
self.path = path

def __str__(self):
return 'empty entry in config: `{path}`'.format(path=self.path)


def merge_dict_deeply(posterior, prior, path=[]):
def try_get(obj, path):
if obj is None:
raise ConfigEmptyEntryException(".".join(path))
return obj

# type: (Dict[str, Any], Dict[str, Any]) -> Dict[str, Any]
tmp = {}

for key in set(posterior.keys()) | set(prior.keys()):
child_path = path + [key]
if key in prior:
if isinstance(prior[key], dict):
tmp[key] = merge_dict_deeply(posterior.get(key, {}), prior[key])
child_posterior = try_get(posterior.get(key, {}), child_path)
tmp[key] = merge_dict_deeply(child_posterior, prior[key],
child_path)
else:
tmp[key] = prior[key]
tmp[key] = try_get(prior[key], child_path)
else:
if isinstance(posterior[key], dict):
tmp[key] = posterior[key].copy()
tmp[key] = try_get(posterior[key], child_path).copy()
else:
tmp[key] = posterior[key]
tmp[key] = try_get(posterior[key], child_path)

return tmp

Expand Down