Skip to content

Commit

Permalink
[fix]tools-v2: panic when show cluster status
Browse files Browse the repository at this point in the history
Signed-off-by: montaguelhz <[email protected]>
  • Loading branch information
montaguelhz authored and caoxianfei1 committed Nov 20, 2023
1 parent b6b06ef commit a63ca11
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
18 changes: 15 additions & 3 deletions tools-v2/internal/error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,12 @@ var (
ErrBsListZone = func() *CmdError {
return NewInternalCmdError(39, "list zone fail. the error is %s")
}

ErrBsDeleteFile = func() *CmdError {
return NewInternalCmdError(40, "delete file fail. the error is %s")
}

ErrRespTypeNoExpected = func() *CmdError {
return NewInternalCmdError(41, "the response type is not as expected, should be: %s")
}

ErrGetPeer = func() *CmdError {
return NewInternalCmdError(42, "invalid peer args, err: %s")
}
Expand Down Expand Up @@ -487,6 +484,21 @@ var (
ErrBsGetFormatStatus = func() *CmdError {
return NewInternalCmdError(75, "get format status fail, err: %s")
}
ErrBsGetSegmentInfo = func() *CmdError {
return NewInternalCmdError(76, "get segment info fail, err: %s")
}
ErrBsGetChunkHash = func() *CmdError {
return NewInternalCmdError(77, "get chunk hash fail, err: %s")
}
ErrBsListSnaspshot = func(requestId, code, message string) *CmdError {
return NewInternalCmdError(78, fmt.Sprintf("list snapshot fail, requestId: %s, code: %s, message: %s", requestId, code, message))
}
ErrBsGetCloneRecover = func() *CmdError {
return NewInternalCmdError(79, "get clone-recover fail, err: %s")
}
ErrInvalidMetaServerAddr = func() *CmdError {
return NewInternalCmdError(80, "invalid metaserver external addr: %s")
}

// http error
ErrHttpUnreadableResult = func() *CmdError {
Expand Down
3 changes: 1 addition & 2 deletions tools-v2/pkg/cli/command/curvefs/status/copyset/copyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ func (cCmd *CopysetCommand) Init(cmd *cobra.Command, args []string) error {
poolIdVec = append(poolIdVec, fmt.Sprintf("%d", info.GetPoolId()))
}
if len(copysetIdVec) == 0 {
var err error
cCmd.Error = cmderror.ErrSuccess()
cCmd.Result = "No copyset found"
cCmd.health = cobrautil.HEALTH_OK
return err
return nil
}
copysetIds := strings.Join(copysetIdVec, ",")
poolIds := strings.Join(poolIdVec, ",")
Expand Down
1 change: 1 addition & 0 deletions tools-v2/pkg/cli/command/curvefs/status/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (eCmd *EtcdCommand) Init(cmd *cobra.Command, args []string) error {
// set main addr
etcdAddrs, addrErr := config.GetFsEtcdAddrSlice(eCmd.Cmd)
if addrErr.TypeCode() != cmderror.CODE_SUCCESS {
eCmd.Error = addrErr
return fmt.Errorf(addrErr.Message)
}
for _, addr := range etcdAddrs {
Expand Down
2 changes: 2 additions & 0 deletions tools-v2/pkg/cli/command/curvefs/status/mds/mds.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ func (mCmd *MdsCommand) Init(cmd *cobra.Command, args []string) error {
// set main addr
mainAddrs, addrErr := config.GetFsMdsAddrSlice(mCmd.Cmd)
if addrErr.TypeCode() != cmderror.CODE_SUCCESS {
mCmd.Error = addrErr
return fmt.Errorf(addrErr.Message)
}

// set dummy addr
dummyAddrs, addrErr := config.GetFsMdsDummyAddrSlice(mCmd.Cmd)
if addrErr.TypeCode() != cmderror.CODE_SUCCESS {
mCmd.Error = addrErr
return fmt.Errorf(addrErr.Message)
}
for _, addr := range dummyAddrs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ func (mCmd *MetaserverCommand) Init(cmd *cobra.Command, args []string) error {

for i, addr := range externalAddrs {
if !config.IsValidAddr(addr) {
return fmt.Errorf("invalid metaserver external addr: %s", addr)
mCmd.Error = cmderror.ErrInvalidMetaServerAddr()
mCmd.Error.Format(addr)
return fmt.Errorf(mCmd.Error.Message)
}

// set metrics
Expand Down

0 comments on commit a63ca11

Please sign in to comment.