diff --git a/CHANGELOG.md b/CHANGELOG.md index 4223b289..a964c498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 to the previous versions. To update existing installations it requires overriding the installed git hook by running `autohooks activate --force`. [#24](https://github.com/greenbone/autohooks/pull/24) +* The installed git hook will fail now if a autohooks plugin can't be executed + e.g. if the import fails. Before these errors were ignored. + [#28](https://github.com/greenbone/autohooks/pull/28) ### Deprecated ### Fixed diff --git a/autohooks/precommit/run.py b/autohooks/precommit/run.py index 2e0f3064..90acba8e 100644 --- a/autohooks/precommit/run.py +++ b/autohooks/precommit/run.py @@ -50,7 +50,7 @@ def has_precommit_function(plugin): def has_precommit_parameters(plugin): signature = inspect.signature(plugin.precommit) - return True if signature.parameters else False + return bool(signature.parameters) def run(): @@ -70,14 +70,18 @@ def run(): plugin = load_plugin(name) if not has_precommit_function(plugin): error( - 'No precommit function found in plugin {}'.format(name) + 'No precommit function found in plugin {}. ' + 'Your autohooks settings may be invalid.'.format(name) ) - return 0 + return 1 if has_precommit_parameters(plugin): retval = plugin.precommit(config=config.get_config()) else: - warning('precommit function without kwargs is deprecated.') + warning( + 'precommit function without kwargs is deprecated. ' + 'Please update {} to a newer version.'.format(name) + ) retval = plugin.precommit() if retval: @@ -86,12 +90,14 @@ def run(): except ImportError as e: error( 'An error occurred while importing pre-commit ' - 'hook {}. {}. The hook will be ignored.'.format(name, e) + 'hook {}. {}.'.format(name, e) ) + return 1 except Exception as e: # pylint: disable=broad-except error( 'An error occurred while running pre-commit ' - 'hook {}. {}. The hook will be ignored.'.format(name, e) + 'hook {}. {}.'.format(name, e) ) + return 1 return 0