Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

fixed issue 1716: No third party error handling in loading plugin RES… #1717

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

candysmurf
Copy link
Contributor

Fixes #1716

Summary of changes:

  • Added default loading plugin error response

Testing done:

  • small, medium and legacy

@intelsdi-x/snap-maintainers

@mkleina
Copy link
Contributor

mkleina commented Aug 17, 2017

Tested your changes (regenerated client-go and CLI) and it seems that go-swagger have some bug (I am using latest swagger release 0.11.0).

When no response code provided, default response code is 200, so the client returns LoadPluginDefault{} type (load_plugin_responses.go):

...
default:
    result := NewLoadPluginDefault(response.Code())
    if err := result.readResponse(response, consumer, o.formats); err != nil {
        return nil, err
    }
    if response.Code()/100 == 2 {
        return result, nil <---------------- HERE
    }
    return nil, result
}

but in LoadPlugin method it casts all results to LoadPluginCreated{} (plugins_client.go):

func (a *Client) LoadPlugin(params *LoadPluginParams, authInfo runtime.ClientAuthInfoWriter) (*LoadPluginCreated, error) {
	// TODO: Validate the params before sending
	if params == nil {
		params = NewLoadPluginParams()
	}

	result, err := a.transport.Submit(&runtime.ClientOperation{
		ID:                 "loadPlugin",
		Method:             "POST",
		PathPattern:        "/plugins",
		ProducesMediaTypes: []string{"application/json"},
		ConsumesMediaTypes: []string{"multipart/form-data"},
		Schemes:            []string{"http", "https"},
		Params:             params,
		Reader:             &LoadPluginReader{formats: a.formats},
		AuthInfo:           authInfo,
		Context:            params.Context,
		Client:             params.HTTPClient,
	})
	if err != nil {
		return nil, err
	}
	return result.(*LoadPluginCreated), nil <--------------- HERE
}

In result, when something go wrong, CLI will throw:

panic: interface conversion: interface {} is *plugins.LoadPluginDefault, not *plugins.LoadPluginCreated

goroutine 1 [running]:
github.com/intelsdi-x/snap-cli/vendor/github.com/intelsdi-x/snap-client-go/client/plugins.(*Client).LoadPlugin(0xc42042df60, 0xc4200a4f00, 0x0, 0x0, 0x0, 0xbf72e0, 0x1)
        /home/mkleina/workspace/go/src/github.com/intelsdi-x/snap-cli/vendor/github.com/intelsdi-x/snap-client-go/client/plugins/plugins_client.go:209 +0x39a
github.com/intelsdi-x/snap-cli/snaptel.loadPlugin(0xc4200949a0, 0x0, 0x0)
        /home/mkleina/workspace/go/src/github.com/intelsdi-x/snap-cli/snaptel/plugin.go:75 +0xa99
github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli.HandleAction(0x8a7400, 0x964a90, 0xc4200949a0, 0xc42009a000, 0x0)
        /home/mkleina/workspace/go/src/github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli/app.go:490 +0xd4
github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli.Command.Run(0x944b0b, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x962691, 0x76, 0x0, ...)
        /home/mkleina/workspace/go/src/github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli/command.go:210 +0xb6e
github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli.(*App).RunAsSubcommand(0xc4200fba00, 0xc420094000, 0x0, 0x0)
        /home/mkleina/workspace/go/src/github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli/app.go:379 +0xacf
github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli.Command.startApp(0x946778, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/mkleina/workspace/go/src/github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli/command.go:298 +0x8fa
github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli.Command.Run(0x946778, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/mkleina/workspace/go/src/github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli/command.go:98 +0x13f3
github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli.(*App).Run(0xc4200fb380, 0xc42000ea00, 0x4, 0x4, 0x0, 0x0)
        /home/mkleina/workspace/go/src/github.com/intelsdi-x/snap-cli/vendor/github.com/urfave/cli/app.go:255 +0x76f
main.main()
        /home/mkleina/workspace/go/src/github.com/intelsdi-x/snap-cli/main.go:49 +0x376

@candysmurf
Copy link
Contributor Author

@mkleina, thanks for the review. May I know the steps to reproduce the error you had?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants