Improve error messages from translation script (#102098)

Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Erik Montnemery 2023-10-22 23:45:27 +02:00 committed by GitHub
parent bc45de627a
commit 164872e1af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 24 deletions

View file

@ -1,4 +1,5 @@
"""Errors for translations."""
import json
class ExitApp(Exception):
@ -8,3 +9,28 @@ class ExitApp(Exception):
"""Initialize the exit app exception."""
self.reason = reason
self.exit_code = exit_code
class JSONDecodeErrorWithPath(json.JSONDecodeError):
"""Subclass of JSONDecodeError with additional properties.
Additional properties:
path: Path to the JSON document being parsed
"""
def __init__(self, msg, doc, pos, path):
"""Initialize."""
lineno = doc.count("\n", 0, pos) + 1
colno = pos - doc.rfind("\n", 0, pos)
errmsg = f"{msg}: file: {path} line {lineno} column {colno} (char {pos})"
ValueError.__init__(self, errmsg)
self.msg = msg
self.doc = doc
self.pos = pos
self.lineno = lineno
self.colno = colno
self.path = path
def __reduce__(self):
"""Reduce."""
return self.__class__, (self.msg, self.doc, self.pos, self.path)