Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chrisyxlee opened this issue Jul 29, 2024 · 0 comments · May be fixed by #21

Comments

@chrisyxlee
Copy link

chrisyxlee commented Jul 29, 2024

} 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/[email protected]/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. 😅

@chrisyxlee chrisyxlee linked a pull request Dec 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant