Skip to content

bad character range in a file skip glob #2145

Closed
@peternewman

Description

@peternewman

Also, as result codespell --skip "example file with actual [weird signs in it and b-a]" goes down with

Traceback (most recent call last):
  File "/home/mateusz/.local/bin/codespell", line 8, in <module>
    sys.exit(_script_main())
  File "/home/mateusz/.local/lib/python3.8/site-packages/codespell_lib/_codespell.py", line 748, in _script_main
    return main(*sys.argv[1:])
  File "/home/mateusz/.local/lib/python3.8/site-packages/codespell_lib/_codespell.py", line 876, in main
    if glob_match.match(root):  # skip (absolute) directories
  File "/home/mateusz/.local/lib/python3.8/site-packages/codespell_lib/_codespell.py", line 108, in match
    if fnmatch.fnmatch(filename, p):
  File "/usr/lib/python3.8/fnmatch.py", line 36, in fnmatch
    return fnmatchcase(name, pat)
  File "/usr/lib/python3.8/fnmatch.py", line 70, in fnmatchcase
    match = _compile_pattern(pat)
  File "/usr/lib/python3.8/fnmatch.py", line 46, in _compile_pattern
    return re.compile(res).match
  File "/usr/lib/python3.8/re.py", line 252, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.8/sre_parse.py", line 834, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "/usr/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.8/sre_parse.py", line 598, in _parse
    raise source.error(msg, len(this) + 1 + len(that))
re.error: bad character range b-a at position 56

_Originally posted by @matkoniecz in #2142 (comment)

While that glob obviously won't work, we probably shouldn't crash quite so unhelpfully and instead catch the error...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions