Skip to content

Commit 8d5d7b0

Browse files
kristian-clausalxxyzz
authored andcommitted
Add new error message categories: NOTE and WIKI
NOTE is for general messages that don't fit in debug, and isn't really a warning or error. WIKI is for everything that's wrong on the Wiki source side of things, in cases where we have already corrected the issue on our side. Wiktionary errors in arguments, etc.
1 parent a979ada commit 8d5d7b0

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

src/wikitextprocessor/core.py

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class CollatedErrorReturnData(TypedDict):
107107
errors: list[ErrorMessageData]
108108
warnings: list[ErrorMessageData]
109109
debugs: list[ErrorMessageData]
110+
notes: list[ErrorMessageData]
111+
wiki_notices: list[ErrorMessageData]
110112

111113

112114
CookieData = tuple[str, Sequence[str], bool]
@@ -275,6 +277,8 @@ class Wtp:
275277
"paired_html_tags",
276278
"inside_html_tags_re",
277279
"parser_function_aliases",
280+
"notes", # NOTE error messages
281+
"wiki_notices", # WIKI error messages
278282
)
279283

280284
def __init__(
@@ -295,6 +299,8 @@ def __init__(
295299
self.errors: list[ErrorMessageData] = []
296300
self.warnings: list[ErrorMessageData] = []
297301
self.debugs: list[ErrorMessageData] = []
302+
self.notes: list[ErrorMessageData] = []
303+
self.wiki_notices: list[ErrorMessageData] = []
298304
self.section: Optional[str] = None
299305
self.subsection: Optional[str] = None
300306
self.lua: Optional["LuaRuntime"] = None
@@ -571,6 +577,50 @@ def debug(
571577
)
572578
self._fmt_errmsg("DEBUG", msg, trace)
573579

580+
def note(
581+
self, msg: str, trace: Optional[str] = None, sortid="XYZunsorted"
582+
) -> None:
583+
"""Prints a note message to stdout. The error is also saved in
584+
self.notes."""
585+
assert isinstance(msg, str)
586+
assert isinstance(trace, (str, type(None)))
587+
assert isinstance(sortid, str)
588+
589+
self.notes.append(
590+
{
591+
"msg": msg,
592+
"trace": trace or "",
593+
"title": self.title or "ERROR_TITLE",
594+
"section": self.section or "",
595+
"subsection": self.subsection or "",
596+
"called_from": sortid,
597+
"path": tuple(self.expand_stack),
598+
}
599+
)
600+
self._fmt_errmsg("NOTE", msg, trace)
601+
602+
def wiki_notice(
603+
self, msg: str, trace: Optional[str] = None, sortid="XYZunsorted"
604+
) -> None:
605+
"""Prints a wiki-related note message to stdout. The error is also
606+
saved in self.notes."""
607+
assert isinstance(msg, str)
608+
assert isinstance(trace, (str, type(None)))
609+
assert isinstance(sortid, str)
610+
611+
self.wiki_notices.append(
612+
{
613+
"msg": msg,
614+
"trace": trace or "",
615+
"title": self.title or "ERROR_TITLE",
616+
"section": self.section or "",
617+
"subsection": self.subsection or "",
618+
"called_from": sortid,
619+
"path": tuple(self.expand_stack),
620+
}
621+
)
622+
self._fmt_errmsg("WIKI", msg, trace)
623+
574624
def to_return(self) -> CollatedErrorReturnData:
575625
"""Returns a dictionary with errors, warnings, and debug messages
576626
from the context. Note that the values are reset whenever starting
@@ -580,6 +630,8 @@ def to_return(self) -> CollatedErrorReturnData:
580630
"errors": self.errors,
581631
"warnings": self.warnings,
582632
"debugs": self.debugs,
633+
"notes": self.notes,
634+
"wiki_notices": self.wiki_notices,
583635
}
584636

585637
def _canonicalize_parserfn_name(self, name: str) -> str:
@@ -1005,16 +1057,18 @@ def set_template_pre_expand(self, name: str) -> None:
10051057
)
10061058

10071059
def start_page(self, title: str) -> None:
1008-
"""Starts a new page for expanding Wikitext. This saves the title and
1009-
full page source in the context. Calling this is mandatory
1010-
for each page; expand_wikitext() can then be called multiple
1011-
times for the same page. This clears the self.errors,
1012-
self.warnings, and self.debugs lists and any current section
1013-
or subsection."""
1060+
"""Starts a new page for expanding Wikitext. This saves the title
1061+
and full page source in the context. Calling this is mandatory for
1062+
each page; expand_wikitext() can then be called multiple times for the
1063+
same page. This clears the self.errors, self.warnings, self.debugs,
1064+
self.notes and self.wiki_notices lists and any current section or
1065+
subsection."""
10141066
self.title = title
10151067
self.errors = []
10161068
self.warnings = []
10171069
self.debugs = []
1070+
self.notes = []
1071+
self.wiki_notices = []
10181072
self.section = None
10191073
self.subsection = None
10201074
self.cookies = []

0 commit comments

Comments
 (0)