Skip to content

Malformed regex in a syntax rule bypasses the reraise_exceptions setting and throws uncaught on every file open/save #164

Description

@dpc00

What happens

reraise_exceptions (default false) is documented as suppressing console errors from rule matching unless explicitly enabled. Two of the three rule-matching code paths honor it correctly (glob_matches and function_matches in ApplySyntax.py both catch exceptions and check self.reraise_exceptions). The third path, plain regex rule matching (regexp_matches, used for first_line/interpreter/file_path/contains rules), has no exception handling at all — a malformed pattern raises re.error directly from re.match/re.search, uncaught, regardless of the setting.

Repro steps

  1. Add a rule to ApplySyntax's User settings under "syntaxes":
    {
      "name": "BadRegexTest",
      "syntax": "Packages/Text/Plain text.tmLanguage",
      "rules": [{"first_line": "(unclosed["}]
    }
  2. Open (or save) any file — this rule has no extensions filter so it's evaluated for every file.
  3. The console shows an uncaught re.error from regexp_matches, even with reraise_exceptions left at its default false.

Suggested fix

Wrap the re.match/re.search call in regexp_matches in the same try/except + reraise_exceptions check already used in glob_matches and function_matches.

Found via source review + a live test that was interrupted by an unrelated local environment issue before the exact traceback could be captured on this machine, but the code path is unambiguous — happy to help verify further if useful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S: triageIssue needs triage.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions