• Bruce Dawson's avatar
    Don't halt presubmits on exceptions · 10a82868
    Bruce Dawson authored
    Some presubmit failures result in uncaught exceptions which historically
    have halted presubmit runs. This behavior makes it more difficult to
    find all failures, measure presubmit times, or detect other behavior
    over time. This is particularly problematic when running "git cl
    presubmit --all".
    
    As an example, presubmit --all was broken and would not complete from
    when crrev.com/3642633 landed until crrev.com/c/3657600. The minimal
    repro was this presubmit command:
    
        git cl presubmit --files ui\accessibility\ax_mode.h
    
    This command, or presubmit --all, triggered this error, which halts the
    presubmits:
    
    Evaluation of CheckChangeOnCommit failed: [Errno 2] No such file or directory: 'chrome/browser/resources/accessibility/accessibility.js'
    Traceback (most recent call last):
      File "presubmit_support.py", line 2038, in <module>
        sys.exit(main())
      File "presubmit_support.py", line 2015, in main
        return DoPresubmitChecks(
      File "presubmit_support.py", line 1738, in DoPresubmitChecks
        results += executer.ExecPresubmitScript(presubmit_script, filename)
      File "presubmit_support.py", line 1602, in ExecPresubmitScript
        self._run_check_function(function_name, context, sink,
      File "presubmit_support.py", line 1640, in _run_check_function
        six.reraise(e_type, e_value, e_tb)
      File "C:\Users\brucedawson\.vpython-root\e726d2\lib\site-packages\six.py", line 686, in reraise
        raise value
      File "presubmit_support.py", line 1630, in _run_check_function
        result = eval(function_name + '(*__args)', context)
      File "<string>", line 1, in <module>
      File "PRESUBMIT.py", line 314, in CheckChangeOnCommit
        errs.extend(CheckModesMatch(input_api, output_api))
      File "PRESUBMIT.py", line 283, in CheckModesMatch
        ax_modes_in_js = GetAccessibilityModesFromFile(
      File "PRESUBMIT.py", line 245, in GetAccessibilityModesFromFile
        for line in open(fullpath).readlines():
    FileNotFoundError: [Errno 2] No such file or directory: 'chrome/browser/resources/accessibility/accessibility.js'
    
    With this change the exception is handled and presubmits continue after
    printing this message:
    
    Evaluation of CheckChangeOnCommit failed: [Errno 2] No such file or directory: 'chrome/browser/resources/accessibility/accessibility.js', Traceback (most recent call last):
      File "presubmit_support.py", line 1630, in _run_check_function
        result = eval(function_name + '(*__args)', context)
      File "<string>", line 1, in <module>
      File "PRESUBMIT.py", line 314, in CheckChangeOnCommit
        errs.extend(CheckModesMatch(input_api, output_api))
      File "PRESUBMIT.py", line 283, in CheckModesMatch
        ax_modes_in_js = GetAccessibilityModesFromFile(
      File "PRESUBMIT.py", line 245, in GetAccessibilityModesFromFile
        for line in open(fullpath).readlines():
    FileNotFoundError: [Errno 2] No such file or directory: 'chrome/browser/resources/accessibility/accessibility.js'
    
    That is, the crucial information regarding the failure is printed, but
    subsequent presubmits are not skipped.
    
    Bug: 1309977
    Change-Id: I7cfeda85c830e6c8e567c0df3c50f27af1dbe835
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3653978Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
    Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
    10a82868
presubmit_unittest.py 126 KB