lando_required: decode `bytes` to `str` before passing values to the sentry SDK (Bug 1652904) r=zeid
authorConnor Sheehan <>
Thu, 16 Jul 2020 17:06:33 +0000
changeset 7595 35f393d6769a7b146c5e082aef19b38edac55f4a
parent 7594 5fde0e4a0e44cc61e3d56929102ef4aa0a58b13a
child 7596 c9e10b367ac3ca84f37ad24895d4c66f02ae8259
push id3785
push dateThu, 16 Jul 2020 17:10:11 +0000
treeherderversion-control-tools@35f393d6769a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
lando_required: decode `bytes` to `str` before passing values to the sentry SDK (Bug 1652904) r=zeid The Sentry SDK assumes values passed to it are `str`, whereas most values currently being passed in the Lando required check are `bytes`. This commit decodes all `bytes` values to `str` as utf-8. Differential Revision:
--- a/hghooks/mozhghooks/check/
+++ b/hghooks/mozhghooks/check/
@@ -157,28 +157,31 @@ class LandoRequiredCheck(PreTxnChangegro
         # `sentry_sdk` doesn't like the demandimporter. Deactivate it,
         # and only import when we need to ping Sentry.
         with demandimport.deactivated():
             import sentry_sdk
+            sentry_head = self.head.decode("utf-8")
+            sentry_repo = self.repo_name.decode("utf-8")
             with sentry_sdk.push_scope() as scope:
-                scope.user = {'username': self.user_name}
-                scope.set_tag('repo', self.repo_name)
-                scope.set_tag('scm_level', self.privilege_level)
-                scope.set_extra('changeset', self.head)
-                scope.set_extra('justification', self.justification)
-                scope.set_extra('url', REV_URL % {
-                    'repo': self.repo_name,
-                    'rev': self.head,
+                scope.user = {"username": self.user_name}
+                scope.set_tag("repo", sentry_repo)
+                scope.set_tag("scm_level", self.privilege_level.decode("utf-8"))
+                scope.set_extra("changeset", sentry_head)
+                scope.set_extra("justification", self.justification.decode("utf-8"))
+                scope.set_extra("url", REV_URL % {
+                    "repo": sentry_repo,
+                    "rev": sentry_head,
-                sentry_sdk.capture_message(event_message)
+                sentry_sdk.capture_message(event_message.decode("utf-8"))
         except Exception as e:
             # The Sentry Documentation does not mention any exceptions that it could raise.
             # Inspection of the unified sentry-sdk source code shows that Sentry does not define
             # an exception hierarchy of its own. Therefore, we cannot predict what exceptions
             # might be raised during the connection and reporting phases: we have no choice but
             # to capture all exceptions.
             # If connecting to Sentry or reporting via Sentry fails, we do not want to derail the