From 5eb757a74239ab46dd7953ef18a6400f9cfbe997 Mon Sep 17 00:00:00 2001 From: Haiyang Pan Date: Tue, 29 Oct 2019 16:49:17 +0000 Subject: [PATCH] Skip non-text files for CheckDoNotSubmitInFiles Bug: 1017286 Change-Id: Ibb9f2c94eb87024a3d9b9f334ffa5f8e2429b368 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1881377 Reviewed-by: Dirk Pranke Commit-Queue: Haiyang Pan --- presubmit_canned_checks.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index d22bcd7c5..69a9e90b0 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -140,8 +140,14 @@ def CheckDoNotSubmitInFiles(input_api, output_api): # We want to check every text file, not just source files. file_filter = lambda x : x keyword = 'DO NOT ''SUBMIT' - errors = _FindNewViolationsOfRule(lambda _, line : keyword not in line, - input_api, file_filter) + def DoNotSubmitRule(extension, line): + try: + return keyword not in line + # Fallback to True for non-text content + except UnicodeDecodeError: + return True + + errors = _FindNewViolationsOfRule(DoNotSubmitRule, input_api, file_filter) text = '\n'.join('Found %s in %s' % (keyword, loc) for loc in errors) if text: return [output_api.PresubmitError(text)]