Skip to content

Commit

Permalink
azure/errors: treat traceback_base64 as string (#2131)
Browse files Browse the repository at this point in the history
Save a few characters by decoding it as utf-8 string rather than using
the bytes representation.

Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
  • Loading branch information
cjp256 authored Apr 19, 2023
1 parent d6de22e commit 9e4cb4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cloudinit/sources/azure/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, exception: Exception) -> None:
type(exception), exception, exception.__traceback__
)
)
trace_base64 = base64.b64encode(trace.encode("utf-8"))
trace_base64 = base64.b64encode(trace.encode("utf-8")).decode("utf-8")

self.supporting_data["exception"] = repr(exception)
self.supporting_data["traceback_base64"] = trace_base64
12 changes: 7 additions & 5 deletions tests/unittests/sources/azure/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ def test_unhandled_exception():
source_error = exception

error = errors.ReportableErrorUnhandledException(source_error)
trace = base64.b64decode(error.supporting_data["traceback_base64"]).decode(
"utf-8"
)

quoted_value = quote_csv_value(f"exception={source_error!r}")
assert f"|{quoted_value}|" in error.as_description()
traceback_base64 = error.supporting_data["traceback_base64"]
assert isinstance(traceback_base64, str)

trace = base64.b64decode(traceback_base64).decode("utf-8")
assert trace.startswith("Traceback")
assert "raise ValueError" in trace
assert trace.endswith("ValueError: my value error\n")

quoted_value = quote_csv_value(f"exception={source_error!r}")
assert f"|{quoted_value}|" in error.as_description()

0 comments on commit 9e4cb4f

Please sign in to comment.