Skip to content

Commit

Permalink
improve error reporting in converter
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Jun 14, 2024
1 parent d82c40f commit 0d6746e
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions convert/ibek2to3.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,22 @@ def convert_definition(data: dict) -> dict | None:
# copy the leading keys that are not being changed
copy_verbatim(data, new_data, ["name", "description"])

if "pre_defines" in data:
check_converted(data["pre_defines"])
new_data["pre_defines"] = list_to_dict(data["pre_defines"])
if "args" in data:
new_data["params"] = list_to_dict(data["args"])
else:
raise ConvertedAlready # probably! (or its not a support yaml file)
if "post_defines" in data:
check_converted(data["post_defines"])
new_data["post_defines"] = list_to_dict(data["post_defines"])
try:
if "pre_defines" in data:
check_converted(data["pre_defines"])
new_data["pre_defines"] = list_to_dict(data["pre_defines"])
if "args" in data:
new_data["params"] = list_to_dict(data["args"])
else:
raise ConvertedAlready # probably! (or its not a support yaml file)
if "post_defines" in data:
check_converted(data["post_defines"])
new_data["post_defines"] = list_to_dict(data["post_defines"])
except ConvertedAlready:
raise
except Exception:
print(f"Failed to convert {data}")
raise

# copy the trailing keys that are not being changed
copy_verbatim(
Expand Down Expand Up @@ -187,11 +193,16 @@ def list_to_dict(args: list[dict]) -> dict[str, dict]:
becomes the key in the dictionary
"""
params = CommentedMap()
for arg in args:
name = arg["name"]
del arg["name"]
params[name] = arg
return params
try:
for arg in args:
name = arg["name"]
params[name] = arg.copy()
# name is the param key so we no longer need it
del params[name]["name"]
return params
except Exception:
print(f"Failed to convert {arg}")
raise


if __name__ == "__main__":
Expand Down

0 comments on commit 0d6746e

Please sign in to comment.