[sergo] Sergo Report: Error Pattern Audit - 2026-04-21 #27666
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Sergo - Serena Go Expert. A newer discussion is available at Discussion #27892. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Date: 2026-04-21
Strategy:
error-pattern-audit(new exploration)Success Score: 8/10
Run ID: §24744725220
Executive Summary
This inaugural Sergo run performed a deep static analysis of error handling patterns across the
pkg/workflowpackage — the project's dominant package at ~165k LOC across 700+ Go files. Using Serena's LSP symbol navigation and pattern search tools, the analysis uncovered three concrete, actionable improvements in error construction and aggregation.The most architecturally significant finding is that
ErrorCollector.FormattedError— the preferred multi-error aggregation method per its own docstring — silently discards the error chain when collecting multiple errors. This breakserrors.Is/errors.Asintrospection for all 5 callers in production validation paths. Two supporting findings cover a widespreadfmt.Errorf("%s", ...)anti-pattern (9 sites) and an inconsistent logging guard that causes unnecessary allocations in 40+ hot call sites.No prior Sergo runs exist; this establishes the baseline cache for future strategy selection.
🛠️ Serena Tools Update
Tools Snapshot
Tool Capabilities Used Today
activate_projectget_symbols_overviewcompiler.go,engine.go,workflow_errors.gofind_symbolfind_referencing_symbolsWorkflowValidationErrorsearch_for_patternfmt.Errorf("%s",...),NewValidationError,FormattedError,context.TODO/Backgroundlist_dirpkg/workflowdirectory structure📊 Strategy Selection
Cached Reuse Component (50%)
No prior history — first run. Strategy defaults to exploration.
New Exploration Component (50% → 100% for first run)
Novel Approach: Error-pattern audit targeting
pkg/workflowerror types and their usagefind_symbol,search_for_pattern(regex),find_referencing_symbolserrorlintlinter is likely to accumulatefmt.Errorfanti-patterns and inconsistencies across error constructorspkg/workflow/workflow_errors.goand all files usingNewValidationError,NewConfigurationError,NewOperationError,ErrorCollectorCombined Strategy Rationale
For a first run with no cache, full exploration was used. The error subsystem was chosen as the target because:
workflow_errors.gois a high-traffic, cross-cutting concern (~300 LOC, referenced in 40+ files)errorlintandgocriticlinters create a gap for error anti-patterns to accumulate🔍 Analysis Execution
Codebase Context
pkg/workflow(primary), with spot checks inpkg/cli,pkg/parserworkflow_errors.go, all validation files using error constructors,ErrorCollectorcall sitesFindings Summary
📋 Detailed Findings
High Priority Issues
Finding 1:
ErrorCollector.FormattedErrorsilently loses error chainpkg/workflow/workflow_errors.go:261— When multiple errors are collected,FormattedErrorbuilds a string and wraps it withfmt.Errorf("%s", ...), discarding the error chain.errors.Is/errors.Ascannot traverse through the result. By contrast,ErrorCollector.Error()(line 225) correctly useserrors.Join(c.errors...).The method is documented as preferred over
Error(), yet is architecturally weaker. It is called in 5 production validation paths:call_workflow_validation.go:178dispatch_workflow_validation.go:138dispatch_repository_validation.go:100repository_features_validation.go:155strict_mode_validation.go:88Fix: Use
fmt.Errorf("Found %d %s errors:\n%w", len(c.errors), category, errors.Join(c.errors...))to preserve both the formatted header and the full error chain.Medium Priority Issues
Finding 2:
fmt.Errorf("%s", ...)anti-pattern — 9 occurrencesNine call sites use
fmt.Errorf("%s", someString)where no error is being wrapped. The correct idiom iserrors.New(someString).workflow_errors.goengine_validation.gotemplate_injection_utils.gopermissions_validation.godangerous_permissions_validation.gosafe_update_enforcement.gotools_validation_github_toolsets.goruntime_validation.goengine_definition.goThe
perfsprintlinter (enabled in.golangci.yml) targets exactly this. Note: Finding 2 atworkflow_errors.go:261overlaps with Finding 1 — fixing the chain issue also fixes the anti-pattern there.Finding 3: Unconditional log calls in
NewValidationErrorandNewConfigurationErrorNewValidationError(line 66) andNewConfigurationError(line 171) unconditionally callerrorHelpersLog.Printf(...), whileNewOperationError(line 118) correctly guards withif errorHelpersLog.Enabled().NewValidationErrorhas 40+ call sites, many in tight validation loops inside the compiler.✅ Improvement Tasks Generated
Task 1: Fix
ErrorCollector.FormattedErrorto preserve error chainIssue Type: Error Aggregation Correctness
Severity: High | Effort: Small
Before (
pkg/workflow/workflow_errors.go:254-261):After:
Validation: Add tests asserting
errors.Is/errors.Aswork onFormattedErroroutput when multiple errors collected.Task 2: Replace
fmt.Errorf("%s", ...)witherrors.New(...)(8 remaining sites)Issue Type: Error Construction Anti-Pattern
Severity: Medium | Effort: Small
Simple mechanical replacement across 8 files. No behavior change. Aligns with
perfsprintlinter intent and improves code clarity.Task 3: Add
errorHelpersLog.Enabled()guard toNewValidationErrorandNewConfigurationErrorIssue Type: Performance / Code Consistency
Severity: Medium | Effort: Small
Before:
After:
📈 Success Metrics
This Run
Reasoning for Score
📊 Historical Context
Cumulative Statistics (after run 1)
error-pattern-audit🎯 Recommendations
Immediate Actions
ErrorCollector.FormattedError— restore error chain in multi-error aggregation (5 affected callers)fmt.Errorf("%s", ...)→errors.New(...)— 8 remaining sites after fixing rejig docs #1Enabled()guard toNewValidationError/NewConfigurationError— eliminate unnecessary allocations in 40+ call sitesLong-term Improvements
errorlintonce the golangci-lint v2 config bug is resolved — it would catch thefmt.Errorfanti-patterns automaticallyfmt.Errorf("%s", ...)in the meantimeerrors.Is/errors.AsonFormattedErroroutputs to prevent regressions🔄 Next Run Preview
Suggested Focus Areas
error. Check whether interface contracts (e.g.Validatorinterface patterns) are consistently implemented.context.Background()internally (e.g.,action_resolver.go:106,safe_outputs_actions.go:290). Audit whether caller-supplied contexts should be threaded through instead.Strategy Evolution
Next run should blend 50% reuse of
error-pattern-audit(targeting the 8 remainingfmt.Errorf("%s",...)sites for verification) with 50% new exploration of context propagation patterns or interface consistency.References:
Beta Was this translation helpful? Give feedback.
All reactions