fix: prevent npe by handling checking error in NewAnalysis call (#1365)

If there is an issue in creating the Analysis config when calling
analysis.NewAnalysis, then we want to check before assigning the context to a
potentially nil pointer.

Signed-off-by: Danny Clark <danielclark@google.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Daniel Clark 2025-01-31 09:26:35 -05:00 committed by GitHub
parent 990d723909
commit 83672fa768
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,10 +34,10 @@ func (h *Handler) Analyze(ctx context.Context, i *schemav1.AnalyzeRequest) (
[]string{}, //TODO: add custom http headers in server mode
false, // with stats disable
)
config.Context = ctx // Replace context for correct timeouts.
if err != nil {
return &schemav1.AnalyzeResponse{}, err
}
config.Context = ctx // Replace context for correct timeouts.
defer config.Close()
if config.CustomAnalyzersAreAvailable() {