| 76 | |
| 77 | @define |
| 78 | class _PrettyFormatter: |
| 79 | |
| 80 | _ERROR_MSG = dedent( |
| 81 | """\ |
| 82 | ===[{type}]===({path})=== |
| 83 | |
| 84 | {body} |
| 85 | ----------------------------- |
| 86 | """, |
| 87 | ) |
| 88 | _SUCCESS_MSG = "===[SUCCESS]===({path})===\n" |
| 89 | |
| 90 | def filenotfound_error(self, path, exc_info): |
| 91 | return self._ERROR_MSG.format( |
| 92 | path=path, |
| 93 | type="FileNotFoundError", |
| 94 | body=f"{path!r} does not exist.", |
| 95 | ) |
| 96 | |
| 97 | def parsing_error(self, path, exc_info): |
| 98 | exc_type, exc_value, exc_traceback = exc_info |
| 99 | exc_lines = "".join( |
| 100 | traceback.format_exception(exc_type, exc_value, exc_traceback), |
| 101 | ) |
| 102 | return self._ERROR_MSG.format( |
| 103 | path=path, |
| 104 | type=exc_type.__name__, |
| 105 | body=exc_lines, |
| 106 | ) |
| 107 | |
| 108 | def validation_error(self, instance_path, error): |
| 109 | return self._ERROR_MSG.format( |
| 110 | path=instance_path, |
| 111 | type=error.__class__.__name__, |
| 112 | body=error, |
| 113 | ) |
| 114 | |
| 115 | def validation_success(self, instance_path): |
| 116 | return self._SUCCESS_MSG.format(path=instance_path) |
| 117 | |
| 118 | |
| 119 | @define |