From 49256ff020d4773b33d2904dc0db95b07161b612 Mon Sep 17 00:00:00 2001 From: Victor Zhou Date: Wed, 21 Aug 2019 12:21:38 -0700 Subject: [PATCH] Don't crash when highlighter fails in audit Addresses #227 --- detect_secrets/core/audit.py | 5 ++++- detect_secrets/pre_commit_hook.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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