Skip to content

Limit error message overriding #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyparsing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4547,7 +4547,8 @@ def parseImpl(self, instring, loc, doActions=True):
try:
return self.expr._parse(instring, loc, doActions, callPreParse=False)
except ParseBaseException as pbe:
pbe.msg = self.errmsg
if not isinstance(self, Forward) or self.customName is not None:
pbe.msg = self.errmsg
raise
else:
raise ParseException(instring, loc, "No expression defined", self)
Expand Down
23 changes: 23 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9884,6 +9884,29 @@ def modify_upper(self, tokens):
msg=f"unexpected exception line ({exception_line!r})",
)


def testForwardReferenceException(self):
token = pp.Forward()
num = pp.Word(pp.nums)
num.setName("num")
text = pp.Word(pp.alphas)
text.setName("text")
fail = pp.Regex(r"\\[A-Za-z]*")("name")
def parse_fail(s, loc, toks):
raise pp.ParseFatalException(s, loc, f"Unknown symbol: {toks['name']}")
fail.set_parse_action(parse_fail)
token <<= num | text | fail

# If no name is given, do not intercept error messages
with self.assertRaises(pp.ParseFatalException, msg="Unknown symbol: \\fail"):
token.parse_string("\\fail")

# If name is given, do intercept error messages
token.set_name("token")
with self.assertRaises(pp.ParseFatalException, msg="Expected token, found.*"):
token.parse_string("\\fail")


def testMiscellaneousExceptionBits(self):
pp.ParserElement.verbose_stacktrace = True

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy