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

error_message: remove stack error message #746

Merged
merged 12 commits into from
Jun 18, 2020
7 changes: 4 additions & 3 deletions dm/ctl/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/pingcap/dm/dm/pb"
parserpkg "github.com/pingcap/dm/pkg/parser"
"github.com/pingcap/dm/pkg/terror"

"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -72,7 +73,7 @@ func PrintLines(format string, a ...interface{}) {
func PrettyPrintResponse(resp proto.Message) {
s, err := marshResponseToString(resp)
if err != nil {
PrintLines(errors.ErrorStack(err))
PrintLines(terror.Message(err))
csuzhangxc marked this conversation as resolved.
Show resolved Hide resolved
} else {
fmt.Println(s)
}
Expand All @@ -82,7 +83,7 @@ func PrettyPrintResponse(resp proto.Message) {
func PrettyPrintInterface(resp interface{}) {
s, err := json.MarshalIndent(resp, "", " ")
if err != nil {
PrintLines(errors.ErrorStack(err))
PrintLines(terror.Message(err))
} else {
fmt.Println(string(s))
}
Expand Down Expand Up @@ -147,7 +148,7 @@ func PrettyPrintResponseWithCheckTask(resp proto.Message, subStr string) bool {
}

if err != nil {
fmt.Println(errors.ErrorStack(err))
fmt.Println(terror.Message(err))
} else {
// add indent to make it prettily.
replacedStr = strings.Replace(replacedStr, "detail: {", " \tdetail: {", 1)
Expand Down
6 changes: 3 additions & 3 deletions dm/ctl/master/check_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
"context"
"os"

"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/checker"
"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"
)

// NewCheckTaskCmd creates a CheckTask command
Expand All @@ -44,7 +44,7 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) {
}
content, err := common.GetFileContent(cmd.Flags().Arg(0))
if err != nil {
common.PrintLines("get file content error:\n%v", errors.ErrorStack(err))
common.PrintLines("get file content error:\n%v", terror.Message(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about returning Error directly? for terror, it will contain useful code, class, etc.

return
}

Expand All @@ -57,7 +57,7 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) {
Task: string(content),
})
if err != nil {
common.PrintLines("fail to check task:\n%v", errors.ErrorStack(err))
common.PrintLines("fail to check task:\n%v", terror.Message(err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions dm/ctl/master/list_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"context"
"os"

"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"
)

var (
Expand Down Expand Up @@ -73,7 +73,7 @@ func listMemberFunc(cmd *cobra.Command, _ []string) {

leader, master, worker, err := convertListMemberType(cmd)
if err != nil {
common.PrintLines("%s", errors.ErrorStack(err))
common.PrintLines("%s", terror.Message(err))
}

ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -88,7 +88,7 @@ func listMemberFunc(cmd *cobra.Command, _ []string) {
})

if err != nil {
common.PrintLines("list member failed, error:\n%v", errors.ErrorStack(err))
common.PrintLines("list member failed, error:\n%v", terror.Message(err))
return
}
common.PrettyPrintResponse(resp)
Expand Down
4 changes: 2 additions & 2 deletions dm/ctl/master/migrate_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"os"
"strconv"

"github.com/pingcap/errors"
"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/log"
"github.com/pingcap/dm/pkg/terror"
)

// NewMigrateRelayCmd creates a MigrateRelay command
Expand All @@ -49,7 +49,7 @@ func migrateRelayFunc(cmd *cobra.Command, _ []string) {
binlogName := cmd.Flags().Arg(1)
binlogPos, err := strconv.Atoi(cmd.Flags().Arg(2))
if err != nil {
common.PrintLines(errors.ErrorStack(err))
common.PrintLines(terror.Message(err))
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down
8 changes: 5 additions & 3 deletions dm/ctl/master/offline_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"

"github.com/pingcap/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -65,12 +66,12 @@ func offlineMemberFunc(cmd *cobra.Command, _ []string) {

offlineType, err := convertOfflineMemberType(cmd)
if err != nil {
common.PrintLines("get offline type failed, error:\n%v", errors.ErrorStack(err))
common.PrintLines("get offline type failed, error:\n%v", terror.Message(err))
return
}
name, err := cmd.Flags().GetString("name")
if err != nil {
common.PrintLines("get offline name failed, error:\n%v", errors.ErrorStack(err))
common.PrintLines("get offline name failed, error:\n%v", terror.Message(err))
return
} else if name == "" {
common.PrintLines("a member name must be specified")
Expand All @@ -85,11 +86,12 @@ func offlineMemberFunc(cmd *cobra.Command, _ []string) {
Name: name,
})
if err != nil {
common.PrintLines("offline member failed, error:\n%v", errors.ErrorStack(err))
common.PrintLines("offline member failed, error:\n%v", terror.Message(err))
return
}
if !resp.Result {
common.PrintLines("offline member failed:\n%v", resp.Msg)
return
}
common.PrettyPrintResponse(resp)
}
4 changes: 2 additions & 2 deletions dm/ctl/master/operate_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"context"
"os"

"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"
)

// NewOperateLeaderCmd creates a OperateLeader command
Expand Down Expand Up @@ -70,7 +70,7 @@ func operateLeaderFunc(cmd *cobra.Command, _ []string) {
Op: op,
})
if err != nil {
common.PrintLines("fail to operate leader:\n%v", errors.ErrorStack(err))
common.PrintLines("fail to operate leader:\n%v", terror.Message(err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions dm/ctl/master/operate_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"

"github.com/pingcap/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -59,7 +59,7 @@ func operateSourceFunc(cmd *cobra.Command, _ []string) {
configFile := cmd.Flags().Arg(1)
content, err := common.GetFileContent(configFile)
if err != nil {
common.PrintLines("get file content error:\n%v", errors.ErrorStack(err))
common.PrintLines("get file content error:\n%v", terror.Message(err))
return
}
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -77,7 +77,7 @@ func operateSourceFunc(cmd *cobra.Command, _ []string) {
Op: op,
})
if err != nil {
common.PrintLines("can not update task:\n%v", errors.ErrorStack(err))
common.PrintLines("can not update task:\n%v", terror.Message(err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions dm/ctl/master/pause_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"fmt"
"os"

"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"
)

// NewPauseRelayCmd creates a PauseRelay command
Expand All @@ -44,7 +44,7 @@ func pauseRelayFunc(cmd *cobra.Command, _ []string) {

sources, err := common.GetSourceArgs(cmd)
if err != nil {
common.PrintLines("%s", errors.ErrorStack(err))
common.PrintLines("%s", terror.Message(err))
return
}
if len(sources) == 0 {
Expand All @@ -54,7 +54,7 @@ func pauseRelayFunc(cmd *cobra.Command, _ []string) {

resp, err := common.OperateRelay(pb.RelayOp_PauseRelay, sources)
if err != nil {
common.PrintLines("can not pause relay unit:\n%v", errors.ErrorStack(err))
common.PrintLines("can not pause relay unit:\n%v", terror.Message(err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions dm/ctl/master/pause_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ package master
import (
"os"

"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"
)

// NewPauseTaskCmd creates a PauseTask command
Expand All @@ -44,13 +44,13 @@ func pauseTaskFunc(cmd *cobra.Command, _ []string) {

sources, err := common.GetSourceArgs(cmd)
if err != nil {
common.PrintLines("%s", errors.ErrorStack(err))
common.PrintLines("%s", terror.Message(err))
return
}

resp, err := common.OperateTask(pb.TaskOp_Pause, name, sources)
if err != nil {
common.PrintLines("can not pause task %s:\n%v", name, errors.ErrorStack(err))
common.PrintLines("can not pause task %s:\n%v", name, terror.Message(err))
return
}

Expand Down
5 changes: 3 additions & 2 deletions dm/ctl/master/purge_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/dm/dm/command"
"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"
)

var (
Expand Down Expand Up @@ -63,7 +64,7 @@ func purgeRelayFunc(cmd *cobra.Command, _ []string) {

sources, err := common.GetSourceArgs(cmd)
if err != nil {
fmt.Println(errors.ErrorStack(err))
fmt.Println(terror.Message(err))
return
}
if len(sources) == 0 {
Expand Down Expand Up @@ -145,7 +146,7 @@ func purgeRelayFunc(cmd *cobra.Command, _ []string) {
SubDir: subDir,
})
if err != nil {
common.PrintLines("can not purge relay log files: \n%s", errors.ErrorStack(err))
common.PrintLines("can not purge relay log files: \n%s", terror.Message(err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions dm/ctl/master/resume_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"fmt"
"os"

"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"
)

// NewResumeRelayCmd creates a ResumeRelay command
Expand All @@ -44,7 +44,7 @@ func resumeRelayFunc(cmd *cobra.Command, _ []string) {

sources, err := common.GetSourceArgs(cmd)
if err != nil {
common.PrintLines("%s", errors.ErrorStack(err))
common.PrintLines("%s", terror.Message(err))
return
}
if len(sources) == 0 {
Expand All @@ -54,7 +54,7 @@ func resumeRelayFunc(cmd *cobra.Command, _ []string) {

resp, err := common.OperateRelay(pb.RelayOp_ResumeRelay, sources)
if err != nil {
common.PrintLines("can not resume relay unit:\n%v", errors.ErrorStack(err))
common.PrintLines("can not resume relay unit:\n%v", terror.Message(err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions dm/ctl/master/resume_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ package master
import (
"os"

"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"
)

// NewResumeTaskCmd creates a ResumeTask command
Expand All @@ -44,13 +44,13 @@ func resumeTaskFunc(cmd *cobra.Command, _ []string) {

sources, err := common.GetSourceArgs(cmd)
if err != nil {
common.PrintLines("%s", errors.ErrorStack(err))
common.PrintLines("%s", terror.Message(err))
return
}

resp, err := common.OperateTask(pb.TaskOp_Resume, name, sources)
if err != nil {
common.PrintLines("can not resume task %s:\n%v", name, errors.ErrorStack(err))
common.PrintLines("can not resume task %s:\n%v", name, terror.Message(err))
return
}

Expand Down
6 changes: 3 additions & 3 deletions dm/ctl/master/show_ddl_locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/dm/pkg/terror"

"github.com/pingcap/errors"
"github.com/spf13/cobra"
)

Expand All @@ -45,7 +45,7 @@ func showDDLLocksFunc(cmd *cobra.Command, _ []string) {

sources, err := common.GetSourceArgs(cmd)
if err != nil {
common.PrintLines("%s", errors.ErrorStack(err))
common.PrintLines("%s", terror.Message(err))
return
}

Expand All @@ -57,7 +57,7 @@ func showDDLLocksFunc(cmd *cobra.Command, _ []string) {
Sources: sources,
})
if err != nil {
common.PrintLines("can not show DDL locks for task %s and sources %v:\n%s", taskName, sources, errors.ErrorStack(err))
common.PrintLines("can not show DDL locks for task %s and sources %v:\n%s", taskName, sources, terror.Message(err))
return
}

Expand Down
Loading