From b19ba94556a78db10c315b6eb94c9539a0e1599f Mon Sep 17 00:00:00 2001 From: Alexander Chuprov Date: Tue, 9 Jan 2024 18:34:25 +0300 Subject: [PATCH] [#884] cli: Fix error message for undefined endpoint Signed-off-by: Alexander Chuprov --- cmd/frostfs-cli/internal/client/sdk.go | 4 ++++ pkg/network/address.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cmd/frostfs-cli/internal/client/sdk.go b/cmd/frostfs-cli/internal/client/sdk.go index b3e04e5f..f7c48b87 100644 --- a/cmd/frostfs-cli/internal/client/sdk.go +++ b/cmd/frostfs-cli/internal/client/sdk.go @@ -34,6 +34,10 @@ func GetSDKClientByFlag(cmd *cobra.Command, key *ecdsa.PrivateKey, endpointFlag func getSDKClientByFlag(cmd *cobra.Command, key *ecdsa.PrivateKey, endpointFlag string) (*client.Client, error) { var addr network.Address + if len(viper.GetString(endpointFlag)) == 0 { + return nil, fmt.Errorf("%s is not defined", endpointFlag) + } + err := addr.FromString(viper.GetString(endpointFlag)) if err != nil { return nil, fmt.Errorf("%v: %w", errInvalidEndpoint, err) diff --git a/pkg/network/address.go b/pkg/network/address.go index 8ad28572..aeb64788 100644 --- a/pkg/network/address.go +++ b/pkg/network/address.go @@ -88,6 +88,10 @@ func (a *Address) FromString(s string) error { // multiaddrStringFromHostAddr converts "localhost:8080" to "/dns4/localhost/tcp/8080". func multiaddrStringFromHostAddr(host string) (string, error) { + if len(host) == 0 { + return "", fmt.Errorf("host is empty") + } + endpoint, port, err := net.SplitHostPort(host) if err != nil { return "", err