From: Ardis Lu Date: Fri, 3 Jul 2026 04:01:54 +0000 (-0700) Subject: Refactor to delete `try..catch` blocks X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=219127558aa09c230a594ec93ee150c9ea9dbae9;p=event-hashes Refactor to delete `try..catch` blocks 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. --- diff --git a/index.html b/index.html index 4f36b03..8222911 100644 --- a/index.html +++ b/index.html @@ -334,7 +334,9 @@ const eventRegex = strict ? /^(event )(?[a-zA-Z$_][a-zA-Z0-9$_]*) *\((?.*?)(?!.+\))/ : /^(event )?(?[a-zA-Z$_][a-zA-Z0-9$_]*) *\((?.*?)(?!.+\))/; - 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)[]'] @@ -389,22 +391,18 @@ 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; }