Introduced error management to prevent crashes and added prints for error reporting during runtime
This commit is contained in:
@@ -3,12 +3,16 @@ def resolveItem(action, item):
|
||||
if hasattr(action, "resolve"):
|
||||
for label, keys in action.resolve["get"].items():
|
||||
target = item
|
||||
try:
|
||||
for key in keys:
|
||||
target = target[key]
|
||||
|
||||
for key in keys:
|
||||
target = target.get(key)
|
||||
#target = target[key]
|
||||
except (KeyError, IndexError) as error:
|
||||
print(f"Resolver target key/index {error} not found during {action.name}")
|
||||
target = None
|
||||
|
||||
resolved[label] = target
|
||||
|
||||
if "construct" in action.resolve:
|
||||
for label2, piece in action.resolve["construct"].items():
|
||||
constructed = ""
|
||||
@@ -21,6 +25,7 @@ def resolveItem(action, item):
|
||||
constructed += str(item)
|
||||
|
||||
resolved[label2] = constructed
|
||||
|
||||
if "transform" in action.resolve:
|
||||
for source, mutation in action.resolve["transform"].items():
|
||||
for key, value in mutation.items():
|
||||
@@ -80,4 +85,56 @@ def resolveItem2(action, item):
|
||||
|
||||
resolved[source] = deconstructed
|
||||
|
||||
return resolved
|
||||
|
||||
def extractItem(action, item, resolved):
|
||||
if hasattr(action, "extract"):
|
||||
for label, keys in action.extract["get"].items():
|
||||
#resolved[label] = {}
|
||||
target = item
|
||||
try:
|
||||
for key in keys:
|
||||
#if isinstance(target, dict):
|
||||
#.get not compatible with resolving through lists
|
||||
#target = target.get(key)
|
||||
|
||||
#if isinstance(target, list):
|
||||
#regular key not compatible with resolving potentially unknown values like upload image
|
||||
target = target[key]
|
||||
|
||||
except (KeyError, IndexError) as error:
|
||||
print(f"Resolver target key/index {error} not found during {action.name}")
|
||||
target = None
|
||||
|
||||
print("EXTRACT MODULE TEST")
|
||||
print(target)
|
||||
resolved[label] = target
|
||||
if "construct" in action.extract:
|
||||
for label2, piece in action.extract["construct"].items():
|
||||
constructed = ""
|
||||
|
||||
for item in piece:
|
||||
if isinstance(item, dict):
|
||||
for key, value in item.items():
|
||||
item = resolved[value]
|
||||
|
||||
constructed += str(item)
|
||||
|
||||
resolved[label2] = constructed
|
||||
if "transform" in action.extract:
|
||||
for source, mutation in action.extract["transform"].items():
|
||||
for key, value in mutation.items():
|
||||
if resolved[source] == key:
|
||||
resolved[source] = value
|
||||
|
||||
if "deconstruct" in action.extract:
|
||||
for source, mutation in action.extract["deconstruct"].items():
|
||||
deconstructed = str(resolved[source])
|
||||
|
||||
for item in mutation:
|
||||
|
||||
deconstructed = deconstructed.replace(str(item), "")
|
||||
|
||||
resolved[source] = deconstructed
|
||||
|
||||
return resolved
|
||||
Reference in New Issue
Block a user