codecov / engineering-team

This is a general repo to use with GH Projects
1 stars 1 forks source link

[worker] Using `\` in Windows paths in path fixer rules causes the parser to crash #3036

Open drazisil-codecov opened 1 day ago

drazisil-codecov commented 1 day ago

Using \ in Windows paths in path fixer rules causes the parser to crash

This rule:

fixes:
  - 'D:\a\hazelcast-csharp-client\::'
  - '/home/runner/work/hazelcast-csharp-client/::'

Caused this crash:

Traceback (most recent call last):
  File "/worker/services/report/__init__.py", line 647, in build_report_from_raw_content
    result.report = process_raw_upload(self.current_yaml, raw_report, session)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/tracing_utils.py", line 679, in func_with_tracing
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/worker/services/report/raw_upload_processor.py", line 44, in process_raw_upload
    path_fixer = PathFixer.init_from_user_yaml(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/tracing_utils.py", line 679, in func_with_tracing
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/worker/services/path_fixer/__init__.py", line 65, in init_from_user_yaml
    return cls(
           ^^^^
  File "/worker/services/path_fixer/__init__.py", line 85, in __init__
    self.custom_fixes = UserPathFixes(self.yaml_fixes)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/worker/services/path_fixer/user_path_fixes.py", line 48, in __init__
    self.sub_regex = re.compile(
                     ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/__init__.py", line 228, in compile
    return _compile(pattern, flags)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/__init__.py", line 307, in _compile
    p = _compiler.compile(pattern, flags)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/_compiler.py", line 745, in compile
    p = _parser.parse(p, flags)
        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/_parser.py", line 979, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/_parser.py", line 460, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/_parser.py", line 862, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/_parser.py", line 460, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/_parser.py", line 544, in _parse
    code = _escape(source, this, state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/_parser.py", line 443, in _escape
    raise source.error("bad escape %s" % escape, len(escape))
re.error: bad escape \h at position 6

Originally posted by @drazisil-codecov in #532

eliatcodecov commented 18 hours ago
  - 'D:\a\hazelcast-csharp-client\::'

My guess: we're not escaping "\" properly. If this is the problem, we can either ask the user to escape windows paths, or we can try to accommodate these paths in our parser.