You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we try to execute a plugin schema validation using kongClient.Plugins.Validate(ctx, plugin) but Kong, for some reason, is unreachable (incorrect host, port...) go-kong is getting a nil pointer deference panic the application.
I created a sample project to reproduce the problem here. I used go1.17 and go-kong version v0.28.1.
Doing some research, I think I found where go-kong is getting this nil deference error. In plugin_service.go, we have this snippet:
...resp, err: =s.client.Do(ctx, req, nil)
iferr!=nil {
// Arguably Kong should return a 422 Unprocessable Entity for a well-formed// HTTP request with a mangled plugin, but it doesn't, it returns a 400.// Hopefully (usually) we get a 400 because of a mangled plugin rather than// a mangled request, but we can't easily tell as messageFromBody masks errorsifresp.StatusCode==http.StatusBadRequest {
varapiError*APIErrorok: =errors.As(err, &apiError)
if!ok {
returnfalse, "", err
}
returnfalse, apiError.message, nil
}
returnfalse, "", err...
If kong is not reachable, the resp var in resp, err: = s.client.Do(ctx, req, nil) is nil and the err is not nil. However, even with resp == nil, go-kong is checking the status code here: if resp.StatusCode == http.StatusBadRequest { causing the nil deference error. I don't know if there's more parts that could have this kind of error in go-kong. I only have used the plugin validation until now.
The text was updated successfully, but these errors were encountered:
When we try to execute a plugin schema validation using
kongClient.Plugins.Validate(ctx, plugin)
but Kong, for some reason, is unreachable (incorrect host, port...) go-kong is getting anil pointer deference
panic the application.The equivalent curl is this:
I created a sample project to reproduce the problem here. I used go1.17 and go-kong version v0.28.1.
Doing some research, I think I found where go-kong is getting this nil deference error. In
plugin_service.go
, we have this snippet:If kong is not reachable, the
resp
var inresp, err: = s.client.Do(ctx, req, nil)
is nil and the err is not nil. However, even withresp == nil
, go-kong is checking the status code here:if resp.StatusCode == http.StatusBadRequest {
causing the nil deference error. I don't know if there's more parts that could have this kind of error in go-kong. I only have used the plugin validation until now.The text was updated successfully, but these errors were encountered: