Skip to content

Refactor duplicate error-checking pattern in wasm compile function#6

Merged
Tasty-Kiwi merged 4 commits into
wasm-playgroundfrom
copilot/sub-pr-4-again
Feb 7, 2026
Merged

Refactor duplicate error-checking pattern in wasm compile function#6
Tasty-Kiwi merged 4 commits into
wasm-playgroundfrom
copilot/sub-pr-4-again

Conversation

Copilot AI commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Addresses code review feedback from #4 to eliminate duplicate error-checking logic in wasm/wasm.go.

Changes

  • Extracted processAlerts helper function - Consolidates logic for checking alerts, detecting errors, formatting messages, and either returning errors or accumulating warnings
  • Replaced three identical 15-line blocks with single-line calls to processAlerts after lexer, parser, and walker stages
  • Used errors.New for error creation - Avoids potential format specifier issues when wrapping pre-formatted alert strings

Before/After

// Before: Repeated 3 times
if len(l.GetAlerts()) > 0 {
    hasError := false
    for _, a := range l.GetAlerts() {
        if a.AlertType() == alerts.Error {
            hasError = true
            break
        }
    }
    msg := formatAlerts(l.GetAlerts(), code)
    if hasError {
        return "", fmt.Errorf("%s", msg)
    }
    warnings.WriteString(msg)
}

// After: Single helper function, called 3 times
if err := processAlerts(l.GetAlerts(), code, &warnings); err != nil {
    return "", err
}

Net reduction: ~42 lines


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 7, 2026 16:06
Co-authored-by: Tasty-Kiwi <26067386+Tasty-Kiwi@users.noreply.github.com>
Co-authored-by: Tasty-Kiwi <26067386+Tasty-Kiwi@users.noreply.github.com>
Co-authored-by: Tasty-Kiwi <26067386+Tasty-Kiwi@users.noreply.github.com>
Copilot AI changed the title [WIP] Add changes to address review feedback for wasm-playground merge Refactor duplicate error-checking pattern in wasm compile function Feb 7, 2026
Copilot AI requested a review from Tasty-Kiwi February 7, 2026 16:09
@Tasty-Kiwi Tasty-Kiwi marked this pull request as ready for review February 7, 2026 16:10
@Tasty-Kiwi Tasty-Kiwi merged commit 2f6d982 into wasm-playground Feb 7, 2026
@Tasty-Kiwi Tasty-Kiwi deleted the copilot/sub-pr-4-again branch February 7, 2026 16:26
Tasty-Kiwi added a commit that referenced this pull request Feb 7, 2026
* Initial plan

* Extract duplicate error-checking pattern into processAlerts helper

Co-authored-by: Tasty-Kiwi <26067386+Tasty-Kiwi@users.noreply.github.com>

* Remove unnecessary format string in processAlerts

Co-authored-by: Tasty-Kiwi <26067386+Tasty-Kiwi@users.noreply.github.com>

* Use errors.New instead of fmt.Errorf for pre-formatted strings

Co-authored-by: Tasty-Kiwi <26067386+Tasty-Kiwi@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Tasty-Kiwi <26067386+Tasty-Kiwi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants