Skip to content

Commit

Permalink
Improve ErrorCollector formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
phackstock committed Jan 23, 2024
1 parent 211c417 commit 1081d4a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions nomenclature/error.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import textwrap
from collections import namedtuple

pydantic_custom_error_config = {
Expand Down Expand Up @@ -55,8 +56,12 @@ def append(self, error: Exception) -> None:

def __repr__(self) -> str:
error = "error" if len(self.errors) == 1 else "errors"
return f"Collected {len(self.errors)} {error}:\n" + "\n\t".join(
str(error) for error in self.errors
error_list_str = "\n".join(
f"{i+1}. {error}" for i, error in enumerate(self.errors)
)

return f"Collected {len(self.errors)} {error}:\n" + textwrap.indent(
error_list_str, prefix=" "
)

def __bool__(self) -> bool:
Expand Down

0 comments on commit 1081d4a

Please sign in to comment.