Commit db8622bc authored by Bruce Dawson's avatar Bruce Dawson Committed by LUCI CQ

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/+/3566436Reviewed-by: 's avatarJochen Eisinger <jochen@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
parent 017544dc
......@@ -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])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment