From 3e36e6c410fbaf08907d5c4154ca46c52984cd1a Mon Sep 17 00:00:00 2001 From: Jeffrey Lovitz Date: Thu, 25 Jun 2020 14:06:24 -0400 Subject: [PATCH] Capture struct.error exceptions on value encoding --- redisgraph_bulk_loader/entity_file.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/redisgraph_bulk_loader/entity_file.py b/redisgraph_bulk_loader/entity_file.py index 27222be..13d8c47 100644 --- a/redisgraph_bulk_loader/entity_file.py +++ b/redisgraph_bulk_loader/entity_file.py @@ -48,7 +48,7 @@ def typed_prop_to_binary(prop_val, prop_type): try: numeric_prop = int(prop_val) return struct.pack(format_str + "q", Type.LONG.value, numeric_prop) - except ValueError: + except (ValueError, struct.error): # TODO ugly, rethink if prop_type == Type.LONG: raise SchemaError("Could not parse '%s' as a long" % prop_val) @@ -58,7 +58,7 @@ def typed_prop_to_binary(prop_val, prop_type): numeric_prop = float(prop_val) if not math.isnan(numeric_prop) and not math.isinf(numeric_prop): # Don't accept non-finite values. return struct.pack(format_str + "d", Type.DOUBLE.value, numeric_prop) - except ValueError: + except (ValueError, struct.error): # TODO ugly, rethink if prop_type == Type.DOUBLE: raise SchemaError("Could not parse '%s' as a double" % prop_val) @@ -97,7 +97,7 @@ def inferred_prop_to_binary(prop_val): try: numeric_prop = int(prop_val) return struct.pack(format_str + "q", Type.LONG.value, numeric_prop) - except ValueError: + except (ValueError, struct.error): pass # Try to parse value as a float. @@ -105,7 +105,7 @@ def inferred_prop_to_binary(prop_val): numeric_prop = float(prop_val) if not math.isnan(numeric_prop) and not math.isinf(numeric_prop): # Don't accept non-finite values. return struct.pack(format_str + "d", Type.DOUBLE.value, numeric_prop) - except ValueError: + except (ValueError, struct.error): pass # If field is 'false' or 'true', it is a boolean.