Raised when a configuration file does not follow legal syntax.
| 303 | |
| 304 | |
| 305 | class ParsingError(Error): |
| 306 | """Raised when a configuration file does not follow legal syntax.""" |
| 307 | |
| 308 | def __init__(self, source, *args): |
| 309 | super().__init__(f'Source contains parsing errors: {source!r}') |
| 310 | self.source = source |
| 311 | self.errors = [] |
| 312 | self.args = (source, ) |
| 313 | if args: |
| 314 | self.append(*args) |
| 315 | |
| 316 | def append(self, lineno, line): |
| 317 | self.errors.append((lineno, line)) |
| 318 | self.message += '\n\t[line %2d]: %s' % (lineno, repr(line)) |
| 319 | |
| 320 | def combine(self, others): |
| 321 | for other in others: |
| 322 | for error in other.errors: |
| 323 | self.append(*error) |
| 324 | return self |
| 325 | |
| 326 | @staticmethod |
| 327 | def _raise_all(exceptions: Iterable['ParsingError']): |
| 328 | """ |
| 329 | Combine any number of ParsingErrors into one and raise it. |
| 330 | """ |
| 331 | exceptions = iter(exceptions) |
| 332 | with contextlib.suppress(StopIteration): |
| 333 | raise next(exceptions).combine(exceptions) |
| 334 | |
| 335 | |
| 336 |
no outgoing calls
no test coverage detected
searching dependent graphs…