Skip to content

api_metrics_query_RunMetricQueries: Panic when accessing Errors[0] without checking length for 400 error #20

@chrisyxlee

Description

@chrisyxlee

} else if localVarHttpResponse.StatusCode >= 400 {
var v types.ErrorResponse
err = a.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHttpResponse, newErr
}
if v.Errors[0].Meta.Reason != "" {

  • The panic occurred on line 94, specifically when it tries to access Errors[0] without checking the length of the Errors slice
  • In our go.mod: github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip v1.2.0

I tried querying for the first time and read the documentation in the Getting Started guide. I didn't realize that the region code was case sensitive, so I put in us1 instead of US1, which caused the panic.

runtime error: index out of range [0] with length 0

runtime/debug.Stack()
        runtime/debug/stack.go:24 +0x5e
        runtime/panic.go:770 +0x132
github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip.(*APIClient).RunMetricsQueries(0xc0007e56e0, {{0xc00030e050, 0x1, 0x1}, 0xc0010a6140})
        github.com/SumoLogic-Labs/sumologic-go-sdk/service/cip@v1.2.0/api_metrics_query_RunMetricsQueries.go:94 +0xb0f

The panic went away once I put in US1 instead.

This was extremely hard to debug because the panic made me think the issue was not an environment variable. 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions