mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
Ensure _PresubmitResult._message is text
It is easy to get type confusion and end up passing a list as the message parameter to _PresubmitResult. This error will not be detected until the end of the run - perhaps hours later - when all evidence of where the list came from is lost. This change ensures that the message parameter is a string. If it is not then the exception that is thrown should allow quick identification of the problematic code. This also fixes a presubmit unit test that passed None as the message. We could support that but I don't think that we should. Bug: 1309977 Change-Id: Ifb1d5100d47922b0ebd8bb834caa6fbba690b43c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3566436 Reviewed-by: Jochen Eisinger <jochen@chromium.org> Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
This commit is contained in:
@@ -336,7 +336,7 @@ class _PresubmitResult(object):
|
||||
items: A list of short strings to indicate where errors occurred.
|
||||
long_text: multi-line text output, e.g. from another tool
|
||||
"""
|
||||
self._message = message
|
||||
self._message = _PresubmitResult._ensure_str(message)
|
||||
self._items = items or []
|
||||
self._long_text = _PresubmitResult._ensure_str(long_text.rstrip())
|
||||
|
||||
|
||||
@@ -628,7 +628,7 @@ class PresubmitUnittest(PresubmitTestsBase):
|
||||
' pass\n'
|
||||
' with input_api.CreateTemporaryFile():\n'
|
||||
' pass\n'
|
||||
' return [output_api.PresubmitResult(None, f)\n'
|
||||
' return [output_api.PresubmitResult(\'\', f)\n'
|
||||
' for f in input_api._named_temporary_files]\n'),
|
||||
fake_presubmit)
|
||||
self.assertEqual(['baz', 'quux'], [r._items for r in result])
|
||||
|
||||
Reference in New Issue
Block a user