From 219127558aa09c230a594ec93ee150c9ea9dbae9 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Thu, 2 Jul 2026 21:01:54 -0700 Subject: [PATCH] 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. --- index.html | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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; } -- 2.47.3