File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
localstack_snapshot/snapshots Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 16
16
GlobalReplacementFn = Callable [[str ], str ]
17
17
18
18
19
+ class TransformerException (Exception ):
20
+ pass
21
+
22
+
19
23
class TransformContext :
20
24
_cache : dict
21
25
replacements : list [GlobalReplacementFn ]
@@ -43,6 +47,19 @@ def new_scope(self, scope: str) -> int:
43
47
def _register_serialized_reference_replacement (
44
48
transform_context : TransformContext , * , reference_value : str , replacement : str
45
49
):
50
+ # Provide a better error message for the TypeError if the reference value is not iterable (e.g., float)
51
+ # Example: `TypeError: argument of type 'float' is not iterable`
52
+ # Using a list would throw an AttributeError because `.replace` is not applicable.
53
+ # The snapshot library currently only supports strings for reference replacements
54
+ if not isinstance (reference_value , str ):
55
+ message = (
56
+ f"The reference value { reference_value } of type { type (reference_value )} is not a string."
57
+ f" Consider using `reference_replacement=False` in your transformer"
58
+ f" for the replacement { replacement } because reference replacements are only supported for strings."
59
+ )
60
+ SNAPSHOT_LOGGER .error (message )
61
+ raise TransformerException (message )
62
+
46
63
if '"' in reference_value :
47
64
reference_value = reference_value .replace ('"' , '\\ "' )
48
65
You can’t perform that action at this time.
0 commit comments