Mercurial > hgrepos > Python > libs > data-schema
comparison data_schema/__init__.py @ 15:696b83f29363
Use enum props when printing validation problems
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 07 Jul 2023 02:17:45 +0200 |
| parents | cfb97c7c9e5b |
| children | 2a9e7c4b717e |
comparison
equal
deleted
inserted
replaced
| 14:cfb97c7c9e5b | 15:696b83f29363 |
|---|---|
| 180 hint=None, | 180 hint=None, |
| 181 context=None, | 181 context=None, |
| 182 cause=None, | 182 cause=None, |
| 183 index=None): | 183 index=None): |
| 184 if code is None: | 184 if code is None: |
| 185 raise TypeError("`code' must be given") | 185 raise TypeError("`code' must be given") |
| 186 # check validity | 186 # check validity |
| 187 if code not in ERRORS and code not in WARNINGS: | 187 if code not in ERRORS and code not in WARNINGS: |
| 188 raise ValueError( | 188 raise ValueError( |
| 189 "unknown validation error code: {}".format(code)) | 189 "unknown validation error code: {}".format(code)) |
| 190 self.code = code | 190 self.code = code |
| 214 try: | 214 try: |
| 215 msg = " (" + problem_message(self) + ")" | 215 msg = " (" + problem_message(self) + ")" |
| 216 except LookupError: | 216 except LookupError: |
| 217 msg = "" | 217 msg = "" |
| 218 if self.index is None: | 218 if self.index is None: |
| 219 return "ValidationProblem(code={!r}{}, severity={!r}, hint={}, context=[depth={}]{})".format( | 219 return "ValidationProblem(code={}{}, severity={!r}, hint={}, context=[depth={}]{})".format( |
| 220 self.code, msg, self.severity, self.hint, self.context.depth, self.context) | 220 self.code.name, msg, self.severity, self.hint, self.context.depth, self.context) |
| 221 else: | 221 else: |
| 222 return "ValidationProblem(code={!r}{}, severity={!r}, hint={}, context=[depth={}]{}, index={})".format( | 222 return "ValidationProblem(code={}{}, severity={!r}, hint={}, context=[depth={}]{}, index={})".format( |
| 223 self.code, msg, self.severity, self.hint, self.context.depth, self.context, self.index) | 223 self.code.name, msg, self.severity, self.hint, self.context.depth, self.context, self.index) |
| 224 | 224 |
| 225 | 225 |
| 226 class SchemaError(Exception): | 226 class SchemaError(Exception): |
| 227 """An error within the schema itself""" | 227 """An error within the schema itself""" |
| 228 pass | 228 pass |
