diff --git a/detect_secrets/core/audit.py b/detect_secrets/core/audit.py index 11497d761..949bc3434 100644 --- a/detect_secrets/core/audit.py +++ b/detect_secrets/core/audit.py @@ -614,7 +614,10 @@ def _get_secret_with_context( filename, ) - snippet.highlight_line(raw_secret_value) + try: + snippet.highlight_line(raw_secret_value) + except ValueError: + raise SecretNotFoundOnSpecifiedLineError(secret['line_number']) except SecretNotFoundOnSpecifiedLineError: if not force: raise diff --git a/detect_secrets/pre_commit_hook.py b/detect_secrets/pre_commit_hook.py index 3fc122b47..871be44a2 100644 --- a/detect_secrets/pre_commit_hook.py +++ b/detect_secrets/pre_commit_hook.py @@ -141,7 +141,7 @@ def raise_exception_if_baseline_file_is_unstaged(filename): '--name-only', ], ).split() - except subprocess.CalledProcessError: + except subprocess.CalledProcessError: # pragma: no cover # Since we don't pipe stderr, we get free logging through git. raise ValueError