better error messages and fixups

This commit is contained in:
Manuel Barkhau 2020-10-03 18:36:56 +00:00
parent 2f421daf16
commit f705164e75
7 changed files with 155 additions and 123 deletions

View file

@ -13,6 +13,7 @@ from . import parse
from . import config
from . import rewrite
from . import version
from . import regexfmt
from . import v1version
from .patterns import Pattern
@ -39,7 +40,13 @@ def rewrite_lines(
if non_matched_patterns:
for nmp in non_matched_patterns:
logger.error(f"No match for pattern '{nmp.raw_pattern}'")
logger.error(f"Pattern compiles to regex '{nmp.regexp.pattern}'")
msg = (
"\n# "
+ regexfmt.regex101_url(nmp.regexp.pattern)
+ "\nregex = "
+ regexfmt.pyexpr_regex(nmp.regexp.pattern)
)
logger.error(msg)
raise rewrite.NoPatternMatch("Invalid pattern(s)")
else:
return new_lines