Skip to content

Commit

Permalink
Formatting support for errors/warnings in structured_data.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Dec 6, 2023
1 parent 9a0fba9 commit bac366a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions dcicutils/structured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,25 @@ def resolved_refs(self) -> List[str]:
@staticmethod
def format_issue(issue: dict, original_file: Optional[str] = None) -> str:
def src_string(issue: dict) -> str:
if not isinstance(issue, dict) or not isinstance(issue_src := issue.get("src"), dict):
return ""
show_file = original_file and (original_file.endswith(".zip") or
original_file.endswith(".tgz") or original_file.endswith(".gz"))
issue_src = issue.get("src")
src_file = issue_src.get("file") if show_file else ""
src_type = issue_src.get("type")
src_column = issue_src.get("column")
src_row = issue_src.get("row", 0)
if src_file:
src = f"{os.path.basename(src_file)}{':' if src_type or src_column or src_row > 0 else ''}"
src = f"{os.path.basename(src_file)}"
sep = ":"
else:
src = ""
sep = "."
if src_type:
src += ("." if src else "") + src_type
src += (sep if src else "") + src_type
sep = "."
if src_column:
src += ("." if src else "") + src_column
src += (sep if src else "") + src_column
if src_row > 0:
src += (" " if src else "") + f"[{src_row}]"
if not src:
Expand All @@ -137,6 +141,8 @@ def src_string(issue: dict) -> str:
issue_message = error
elif warning := issue.get("warning"):
issue_message = warning
elif issue.get("truncated"):
return f"Truncated result set | More: {issue.get('more')} | See: {issue.get('details')}"
return f"{src_string(issue)}: {issue_message}" if issue_message else ""

def _load_file(self, file: str) -> None:
Expand Down

0 comments on commit bac366a

Please sign in to comment.