Refactor _CODE_PATTERN in error_codes.py

XMLWordPrintableJSON

    • Server Programmability
    • Fully Compatible
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      mathias@mongodb.com mentioned that the following code snippet in buildscripts/error_codes.py is misleading to the reader

          for p in [
              # All the asserts and their optional variant suffixes
              r"(?:f|i|m|t|u)(?:assert)"
              r"(?:ed)?"
              r"(?:Failed)?"
              r"(?:WithStatus)?"
              r"(?:NoTrace)?"
              r"(?:StatusOK)?"
              r"(?:WithContext)?"
              r"\s*\(",
              r"MONGO_UN(?:REACHABLE|IMPLEMENTED)_TASSERT\(",
              # DBException and AssertionException constructors
              r"(?:DB|Assertion)Exception\s*[({]",
      

      because

      Mixing a list of regexs with implicit string concat feels aggressively misleading to the reader. Python has an option to ignore whitespace in regexes, so if we want to split the regex over multiple lines we should use a single multi-line string. Also we should check if it is faster to use several separate regexes or a single combined regex. The latter is usually better, but that depends on the implementation strategy of the regex engine.

      Consider removing the implicit string concatenation, and investigate if using separate regexes is faster.

      See thread for more context.

            Assignee:
            Mathias Stearn
            Reporter:
            Cedric Sirianni
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: