Skip to content

Commit 96c1c00

Browse files
committed
fixing lint errors
1 parent f912a2a commit 96c1c00

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

pkg/analyze/engine.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,16 @@ func (e *DefaultAnalysisEngine) Analyze(ctx context.Context, bundle *SupportBund
381381
for i, analyzer := range opts.CustomAnalyzers {
382382
spec, err := e.convertAnalyzerToSpec(analyzer)
383383
if err != nil {
384-
klog.Errorf("Failed to convert custom analyzer %d to spec: %v", i, err)
385-
klog.Warningf("Creating failure result for analyzer %d. Supported types: ClusterVersion, DeploymentStatus", i)
384+
// Create local copy of index to avoid loop variable capture
385+
analyzerIndex := i
386+
klog.Errorf("Failed to convert custom analyzer %d to spec: %v", analyzerIndex, err)
387+
klog.Warningf("Creating failure result for analyzer %d. Supported types: ClusterVersion, DeploymentStatus", analyzerIndex)
386388
klog.Warningf("To fix: Check your analyzer configuration and ensure it uses supported types")
387389

388390
// Create a failure result instead of skipping
389391
failureResult := AnalyzerResult{
390392
IsFail: true,
391-
Title: fmt.Sprintf("Custom Analyzer %d - Conversion Failed", i),
393+
Title: fmt.Sprintf("Custom Analyzer %d - Conversion Failed", analyzerIndex),
392394
Message: fmt.Sprintf("Failed to convert analyzer to supported format: %v", err),
393395
Category: "configuration",
394396
Confidence: 1.0,
@@ -439,9 +441,23 @@ func (e *DefaultAnalysisEngine) Analyze(ctx context.Context, bundle *SupportBund
439441
Timestamp: time.Now(),
440442
Recoverable: true,
441443
})
442-
} else {
444+
} else if agentResult != nil {
443445
metadata.ResultCount = len(agentResult.Results)
444446
results.Results = append(results.Results, agentResult.Results...)
447+
448+
// Collect individual analyzer errors from successful agents
449+
if len(agentResult.Errors) > 0 {
450+
metadata.ErrorCount = len(agentResult.Errors)
451+
for _, agentErr := range agentResult.Errors {
452+
results.Errors = append(results.Errors, AnalysisError{
453+
Agent: agent.Name(),
454+
Error: agentErr,
455+
Category: "analyzer_execution",
456+
Timestamp: time.Now(),
457+
Recoverable: true,
458+
})
459+
}
460+
}
445461
}
446462

447463
results.Metadata.Agents = append(results.Metadata.Agents, metadata)
@@ -733,7 +749,7 @@ func (e *DefaultAnalysisEngine) convertAnalyzerToSpec(analyzer *troubleshootv1be
733749

734750
// GenerateAnalyzers creates analyzers from requirement specifications
735751
func (e *DefaultAnalysisEngine) GenerateAnalyzers(ctx context.Context, requirements *RequirementSpec) ([]AnalyzerSpec, error) {
736-
ctx, span := otel.Tracer(constants.LIB_TRACER_NAME).Start(ctx, "AnalysisEngine.GenerateAnalyzers")
752+
_, span := otel.Tracer(constants.LIB_TRACER_NAME).Start(ctx, "AnalysisEngine.GenerateAnalyzers")
737753
defer span.End()
738754

739755
if requirements == nil {

pkg/analyze/generators/generator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,5 +970,10 @@ func (g *AnalyzerGenerator) validateCustomRequirement(req *analyzer.CustomRequir
970970
return validator(req)
971971
}
972972

973+
// Check if we have a template with validator for this type
974+
if template, exists := g.templates[req.Type]; exists && template.Validator != nil {
975+
return template.Validator(req)
976+
}
977+
973978
return nil
974979
}

0 commit comments

Comments
 (0)