Skip to content

Commit

Permalink
Merge pull request #981 from sirosen/flows-error-refinement
Browse files Browse the repository at this point in the history
Further refine error reporting for /flows/validate
  • Loading branch information
sirosen authored May 2, 2024
2 parents d34f9b8 + 3c4a6fb commit 27092b6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20240502_124425_sirosen_flows_error_refinement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Enhancements

* Improve the reporting of errors found by `globus flows validate`
37 changes: 29 additions & 8 deletions src/globus_cli/exception_handling/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,35 @@ def flows_error_hook(exception: globus_sdk.FlowsAPIError) -> None:
details = textwrap.fill(details, width=80)
detail_fields = [PrintableErrorField("detail", details, multiline=True)]
# if it's a list of objects, wrap them into a multiline detail field
else:
detail_fields = [
PrintableErrorField(
"detail",
"\n".join(_pretty_json(detail, compact=True) for detail in details),
multiline=True,
)
]
elif isinstance(details, list):
num_errors = len(details)
if all((isinstance(d, dict) and "loc" in d and "msg" in d) for d in details):
detail_strings = [
(
((data["type"] + " ") if "type" in data else "")
+ f"{_jsonpath_from_pydantic_loc(data['loc'])}: {data['msg']}"
)
for data in details
]
if num_errors == 1:
detail_fields = [PrintableErrorField("detail", detail_strings[0])]
else:
detail_fields = [
PrintableErrorField("detail", f"{num_errors} errors"),
PrintableErrorField(
"errors",
"\n".join(detail_strings),
multiline=True,
),
]
else:
detail_fields = [
PrintableErrorField(
"detail",
"\n".join(_pretty_json(detail, compact=True) for detail in details),
multiline=True,
)
]

write_error_info(
"Flows API Error",
Expand Down
1 change: 1 addition & 0 deletions tests/functional/exception_handling/test_flows_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_flows_generic_hook_on_detail_array(run_line):
assert "This flow contains errors in 1 wait state." in result.stderr
assert "detail:" in result.stderr
assert (
"InvalidAccessPath $.definition.States.y.SecondsPath: "
"Improper access to data in this wait state with expression: $.foo[0]"
in result.stderr
)
Expand Down

0 comments on commit 27092b6

Please sign in to comment.