Skip to content

[Code Quality] Extract repetitive error formatting into helper function in compiler.go #13658

@github-actions

Description

@github-actions

Description

The pkg/workflow/compiler.go file contains a repetitive error formatting pattern that appears approximately 20 times throughout the file. This pattern creates significant code duplication (~300 lines) and makes maintenance difficult.

Current Pattern

Lines throughout the file repeat this structure:

formattedErr := console.FormatError(console.CompilerError{
    Position: console.ErrorPosition{
        File:   markdownPath,
        Line:   1,
        Column: 1,
    },
    Type:    "error",
    Message: err.Error(),
})
return errors.New(formattedErr)

Suggested Changes

Extract this pattern into a reusable helper function:

func formatCompilerError(markdownPath string, err error) error {
    formattedErr := console.FormatError(console.CompilerError{
        Position: console.ErrorPosition{
            File:   markdownPath,
            Line:   1,
            Column: 1,
        },
        Type:    "error",
        Message: err.Error(),
    })
    return errors.New(formattedErr)
}

Usage: Replace ~20 repetitive blocks with:

return formatCompilerError(markdownPath, err)

Files Affected

  • pkg/workflow/compiler.go (~20 occurrences to refactor)

Success Criteria

  • Helper function formatCompilerError created
  • All repetitive error formatting blocks replaced with helper call
  • Code duplication reduced by ~200 lines
  • All existing tests continue to pass
  • No change to error message format or behavior

Impact

  • Maintainability: Reduces code duplication by ~30%
  • Readability: Simplifies error handling patterns
  • Effort: 30 minutes estimated
  • Priority: Medium - Improves code quality without affecting functionality

Source

Extracted from Daily Compiler Code Quality Report - 2026-01-28 discussion #12164

Quote from source:

"Pattern repeated ~20 times throughout the file... Reduces ~300 lines to ~100 lines, improves maintainability"

Priority

Medium - Improves maintainability but not blocking

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 18, 2026, 5:21 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions