Improve error messages from translation script (#102098)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
bc45de627a
commit
164872e1af
8 changed files with 59 additions and 24 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue