From bac366a11146a8f65edf2c616f5dd2d6fbfa53a8 Mon Sep 17 00:00:00 2001 From: David Michaels Date: Wed, 6 Dec 2023 11:58:01 -0500 Subject: [PATCH] Formatting support for errors/warnings in structured_data. --- dcicutils/structured_data.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dcicutils/structured_data.py b/dcicutils/structured_data.py index 358df643e..f7fbf5393 100644 --- a/dcicutils/structured_data.py +++ b/dcicutils/structured_data.py @@ -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: @@ -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: