From 6fc394f93d145c3e2f35cc812c81008004332d50 Mon Sep 17 00:00:00 2001 From: Dirk Pranke Date: Wed, 26 May 2021 23:25:14 +0000 Subject: [PATCH] Fix crash during presubmit checking. If a presubmit happened to generate a crash, the logic we have for reporting the presubmit check times would call `six.reraise()` incorrectly, leading to a second crash. This CL fixes the invocation of the second crash, and also adds an error message to help users tripping over one possible source of the first crash (reading a binary file as text). Bug: 1210746 Change-Id: Ic46f38901b6acf2055b3feb7272dc751dc69037c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2921322 Reviewed-by: Edward Lesmes Commit-Queue: Dirk Pranke --- presubmit_support.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/presubmit_support.py b/presubmit_support.py index 8c72f7e8a..b917a5995 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -1006,6 +1006,12 @@ class AffectedFile(object): self.AbsoluteLocalPath(), 'rU').splitlines() except IOError: pass # File not found? That's fine; maybe it was deleted. + except UnicodeDecodeError: + # log the filename since we're probably trying to read a binary + # file, and shouldn't be. + print('Error reading %s: %s' % (self.AbsoluteLocalPath(), e)) + raise + return self._cached_new_contents[:] def ChangedContents(self, keeplinebreaks=False): @@ -1674,9 +1680,8 @@ class PresubmitExecuter(object): # TODO(crbug.com/953884): replace reraise with native py3: # raise .. from e e_type, e_value, e_tb = sys.exc_info() - six.reraise(e_type, 'Evaluation of %s failed: %s' % (function_name, - e_value), - e_tb) + print('Evaluation of %s failed: %s' % (function_name, e_value)) + six.reraise(e_type, e_value, e_tb) elapsed_time = time_time() - start_time if elapsed_time > 10.0: @@ -1742,7 +1747,7 @@ def DoPresubmitChecks(change, python_version = 'Python %s' % sys.version_info.major if committing: - sys.stdout.write('Running %s presubmit commit checks ...\n' % + sys.stdout.write('Running %s presubmit commit checks ...\n' % python_version) else: sys.stdout.write('Running %s presubmit upload checks ...\n' %