Skip to content

Commit d04a1a1

Browse files
Fix error when creating EventError(...) with message=None (#441)
1 parent 06f72c1 commit d04a1a1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

linode_api4/polling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class EventError(Exception):
1313

1414
def __init__(self, event_id: int, message: Optional[str]):
1515
# Edge case, sometimes the message is populated with an empty string
16-
if len(message) < 1:
16+
if message is not None and len(message) < 1:
1717
message = None
1818

1919
self.event_id = event_id

test/unit/objects/polling_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,17 @@ def test_wait_for_event_finished_failed(
328328
assert err.message == "oh no!"
329329
else:
330330
raise Exception("Expected event error, got none")
331+
332+
def test_event_error(
333+
self,
334+
):
335+
"""
336+
Tests that EventError objects can be constructed and
337+
will be formatted to the correct output.
338+
339+
Tests for regression of TPT-3060
340+
"""
341+
342+
assert str(EventError(123, None)) == "Event 123 failed"
343+
assert str(EventError(123, "")) == "Event 123 failed"
344+
assert str(EventError(123, "foobar")) == "Event 123 failed: foobar"

0 commit comments

Comments
 (0)