Skip to content

Commit b3a47aa

Browse files
authored
Removed Exception msg from InternalFailure (#150)
1 parent ae8533f commit b3a47aa

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/cloudformation_cli_python_lib/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def _serialize(self) -> MutableMapping[str, Any]:
119119

120120
@classmethod
121121
def failed(
122-
cls: Type["ProgressEvent"], error_code: HandlerErrorCode, message: str
122+
cls: Type["ProgressEvent"], error_code: HandlerErrorCode, message: str = ""
123123
) -> "ProgressEvent":
124124
return cls(status=OperationStatus.FAILED, errorCode=error_code, message=message)
125125

src/cloudformation_cli_python_lib/resource.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def wrapper(self: Any, event: MutableMapping[str, Any], context: Any) -> Any:
4646
try:
4747
response = entrypoint(self, event, context)
4848
serialized = json.dumps(response, cls=KitchenSinkEncoder)
49-
except Exception as e: # pylint: disable=broad-except
49+
except Exception: # pylint: disable=broad-except
5050
return ProgressEvent.failed( # pylint: disable=protected-access
51-
HandlerErrorCode.InternalFailure, str(e)
51+
HandlerErrorCode.InternalFailure
5252
)._serialize()
5353
return json.loads(serialized)
5454

@@ -121,12 +121,10 @@ def test_entrypoint(
121121
except _HandlerError as e:
122122
LOG.exception("Handler error")
123123
return e.to_progress_event()
124-
except Exception as e: # pylint: disable=broad-except
124+
except Exception: # pylint: disable=broad-except
125125
LOG.exception("Exception caught")
126-
msg = str(e)
127-
except BaseException as e: # pylint: disable=broad-except
126+
except BaseException: # pylint: disable=broad-except
128127
LOG.critical("Base exception caught (this is usually bad)", exc_info=True)
129-
msg = str(e)
130128
return ProgressEvent.failed(HandlerErrorCode.InternalFailure, msg)
131129

132130
@staticmethod
@@ -214,11 +212,11 @@ def print_or_log(message: str) -> None:
214212
print_or_log("Handler error")
215213
progress = e.to_progress_event()
216214
except Exception as e: # pylint: disable=broad-except
217-
print_or_log("Exception caught")
218-
progress = ProgressEvent.failed(HandlerErrorCode.InternalFailure, str(e))
215+
print_or_log("Exception caught {0}".format(e))
216+
progress = ProgressEvent.failed(HandlerErrorCode.InternalFailure)
219217
except BaseException as e: # pylint: disable=broad-except
220-
print_or_log("Base exception caught (this is usually bad)")
221-
progress = ProgressEvent.failed(HandlerErrorCode.InternalFailure, str(e))
218+
print_or_log("Base exception caught (this is usually bad) {0}".format(e))
219+
progress = ProgressEvent.failed(HandlerErrorCode.InternalFailure)
222220

223221
# use the raw event_data as a last-ditch attempt to call back if the
224222
# request is invalid

tests/lib/resource_test.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ def test_entrypoint_uncaught_exception(resource, exc_cls):
255255
event = patch_and_raise(resource, "_parse_request", exc_cls, resource.__call__)
256256
assert event["status"] == OperationStatus.FAILED
257257
assert event["errorCode"] == HandlerErrorCode.InternalFailure
258-
assert event["message"] == "hahaha"
259258

260259

261260
def test__ensure_serialize_uses_custom_encoder():
@@ -278,16 +277,12 @@ class Unserializable:
278277
return {"foo": Unserializable()}
279278

280279
serialized = wrapped(None, None, None)
281-
event = ProgressEvent.failed(
282-
HandlerErrorCode.InternalFailure,
283-
"Object of type Unserializable is not JSON serializable",
284-
)
280+
event = ProgressEvent.failed(HandlerErrorCode.InternalFailure)
285281
try:
286282
# Python 3.7/3.8
287283
assert serialized == event._serialize()
288284
except AssertionError:
289285
# Python 3.6
290-
event.message = "Object of type 'Unserializable' is not JSON serializable"
291286
assert serialized == event._serialize()
292287

293288

@@ -393,7 +388,6 @@ def test_test_entrypoint_uncaught_exception(resource, exc_cls):
393388
)
394389
assert event.status == OperationStatus.FAILED
395390
assert event.errorCode == HandlerErrorCode.InternalFailure
396-
assert event.message == "hahaha"
397391

398392

399393
def test_test_entrypoint_success():

0 commit comments

Comments
 (0)