]> git.ardis.lu - event-hashes/commitdiff
Refactor to delete `try..catch` blocks
authorArdis Lu <ardisglu@gmail.com>
Fri, 3 Jul 2026 04:01:54 +0000 (21:01 -0700)
committerArdis Lu <ardisglu@gmail.com>
Fri, 3 Jul 2026 04:01:54 +0000 (21:01 -0700)
Using `try..catch` for control flow is inconsistent with the rest of the code and does not feel idiomatic. The block was also scoped too broadly, including too much code and catching all errors.

index.html

index 4f36b039d3c463c5d0fd23898723814861f5c421..8222911bb20b38ce13ee477e25b3032dc4a6352d 100644 (file)
       const eventRegex = strict ?
         /^(event )(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) *\((?<topics>.*?)(?!.+\))/ :
         /^(event )?(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) *\((?<topics>.*?)(?!.+\))/;
-      const { name, topics } = eventRegex.exec(event).groups;
+      const regexResult = eventRegex.exec(event);
+      if (regexResult === null) { return null; }
+      const { name, topics } = regexResult.groups;
 
       // Drop parameter names and extraneous whitespace, if there are any. Preserves tuple parentheses.
       // E.g. "(uint abc, uint256, bool test)[]" --> ['(uint', 'uint256', 'bool)[]']
             continue;
           }
           const lookaheadLine = code.substring(start, end + 1).replaceAll('\n', '');
-          try {
-            const normalizedEvent = normalizeEvent(lookaheadLine, strict);
+          const normalizedEvent = normalizeEvent(lookaheadLine, strict);
+          if (normalizedEvent !== null) {
             originalEvents.push(lookaheadLine);
             events.push(normalizedEvent);
           }
-          catch { }
           continue;
         }
-        try {
-          const normalizedEvent = normalizeEvent(line, strict);
+        const normalizedEvent = normalizeEvent(line, strict);
+        if (normalizedEvent !== null) {
           originalEvents.push(line);
           events.push(normalizedEvent);
         }
-        catch {
-          continue;
-        }
       }
       return events;
     }
This page took 0.037124 seconds and 4 git commands to generate.