Skip to content

[sergo] pkg/workflow/mcp_property_validation.go: redundant double type assertion on lines 45-48 #30932

@github-actions

Description

@github-actions

Problem

In validateMCPRequirements (pkg/workflow/mcp_property_validation.go:43-49), a type assertion is performed twice on the same value:

// Line 45: asserts and discards the result
if _, ok := mcpType.(string); !ok {
    return fmt.Errorf(...)
}
// Line 48: asserts again to extract the value
typeStr = mcpType.(string)

The second assertion on line 48 is safe (it cannot panic because the guard on line 45 returns early if the type is wrong), but it is non-idiomatic Go and wastes one type assertion. The canonical pattern extracts the value in a single assertion.

Location

  • pkg/workflow/mcp_property_validation.go:43-49

Impact

  • Severity: Low
  • Affected code: validateMCPRequirements function
  • Risk: No runtime risk (it cannot panic), but the pattern is non-idiomatic and adds unnecessary complexity. It may also confuse readers since the first assertion looks like it validates but discards a valid value.

Recommendation

Combine the check and extraction into one assertion:

Before:

if hasType {
    if _, ok := mcpType.(string); !ok {
        return fmt.Errorf("tool '%s' mcp configuration 'type' must be a string, got %T...", toolName, mcpType, ...)
    }
    typeStr = mcpType.(string)

After:

if hasType {
    var ok bool
    typeStr, ok = mcpType.(string)
    if !ok {
        return fmt.Errorf("tool '%s' mcp configuration 'type' must be a string, got %T...", toolName, mcpType, ...)
    }

Note: A similar (but intentional) pattern exists on line 29 in validateStringProperty where the value is intentionally discarded after the type check — that case is correct as-is.

Validation

  • Run existing mcp_property_validation tests
  • Verify behavior is identical with the simplified assertion

Estimated Effort: Trivial


Generated by Sergo (Run 3, 2026-05-08) — Run ID: §25537174291

Generated by Sergo - Serena Go Expert · ● 506.4K ·

  • expires on May 15, 2026, 4:52 AM UTC

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!sergo

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions