Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless errors.AddStack #985

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/cluster/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ conflict checks with other clusters`,

exist, err := tidbSpec.Exist(clusterName)
if err != nil {
return perrs.AddStack(err)
return err
}

if !exist {
Expand Down
6 changes: 3 additions & 3 deletions components/cluster/command/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newDisplayCmd() *cobra.Command {

exist, err := tidbSpec.Exist(clusterName)
if err != nil {
return perrs.AddStack(err)
return err
}

if !exist {
Expand All @@ -57,12 +57,12 @@ func newDisplayCmd() *cobra.Command {
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return perrs.AddStack(err)
return err
}
if showDashboardOnly {
tlsCfg, err := metadata.Topology.TLSConfig(tidbSpec.Path(clusterName, spec.TLSCertKeyDir))
if err != nil {
return perrs.AddStack(err)
return err
}
return displayDashboardInfo(clusterName, tlsCfg)
}
Expand Down
3 changes: 1 addition & 2 deletions components/cluster/command/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"path/filepath"

"github.com/fatih/color"
"github.com/pingcap/errors"
"github.com/pingcap/tiup/pkg/cliutil"
"github.com/pingcap/tiup/pkg/cluster/ansible"
"github.com/pingcap/tiup/pkg/cluster/spec"
Expand Down Expand Up @@ -66,7 +65,7 @@ func newImportCmd() *cobra.Command {

exist, err := tidbSpec.Exist(clsName)
if err != nil {
return errors.AddStack(err)
return err
}

if exist {
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func newTestCmd() *cobra.Command {

exist, err := tidbSpec.Exist(clusterName)
if err != nil {
return perrs.AddStack(err)
return err
}

if !exist {
Expand Down
30 changes: 15 additions & 15 deletions components/dm/ansible/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func searchConfigFile(dir string) (fname string, err error) {
func readConfigFile(dir string) (file *ini.File, err error) {
fname, err := searchConfigFile(dir)
if err != nil {
return nil, errors.AddStack(err)
return nil, err
}

file, err = ini.Load(fname)
Expand Down Expand Up @@ -205,7 +205,7 @@ func setConfig(config *map[string]interface{}, k string, v interface{}) {
func (im *Importer) handleWorkerConfig(srv *spec.WorkerSpec, fname string) error {
data, err := im.fetchFile(srv.Host, srv.SSHPort, fname)
if err != nil {
return errors.AddStack(err)
return err
}

config := new(Config)
Expand Down Expand Up @@ -255,7 +255,7 @@ func (im *Importer) ScpSourceToMaster(topo *spec.Specification) (err error) {

err = e.Transfer(f.Name(), filepath.Join(target, addr+".yml"), false)
if err != nil {
return errors.AddStack(err)
return err
}
}
}
Expand All @@ -278,7 +278,7 @@ func (im *Importer) ImportFromAnsibleDir() (clusterName string, meta *spec.Metad

cfg, err := readConfigFile(dir)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}

fname := filepath.Join(dir, inventoryFileName)
Expand Down Expand Up @@ -336,11 +336,11 @@ func (im *Importer) ImportFromAnsibleDir() (clusterName string, meta *spec.Metad
runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_dm-master.sh")
data, err := im.fetchFile(srv.Host, srv.SSHPort, runFileName)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}
deployDir, flags, err := parseRunScript(data)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}

if deployDir == "" {
Expand Down Expand Up @@ -384,11 +384,11 @@ func (im *Importer) ImportFromAnsibleDir() (clusterName string, meta *spec.Metad
runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_dm-worker.sh")
data, err := im.fetchFile(srv.Host, srv.SSHPort, runFileName)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}
deployDir, flags, err := parseRunScript(data)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}

if deployDir == "" {
Expand Down Expand Up @@ -427,7 +427,7 @@ func (im *Importer) ImportFromAnsibleDir() (clusterName string, meta *spec.Metad

err = im.handleWorkerConfig(&srv, configFileName)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}

topo.Workers = append(topo.Workers, srv)
Expand All @@ -445,12 +445,12 @@ func (im *Importer) ImportFromAnsibleDir() (clusterName string, meta *spec.Metad
runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_prometheus.sh")
data, err := im.fetchFile(srv.Host, srv.SSHPort, runFileName)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}

deployDir, flags, err := parseRunScript(data)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}

if deployDir == "" {
Expand Down Expand Up @@ -493,12 +493,12 @@ func (im *Importer) ImportFromAnsibleDir() (clusterName string, meta *spec.Metad
runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_alertmanager.sh")
data, err := im.fetchFile(srv.Host, srv.SSHPort, runFileName)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}

deployDir, flags, err := parseRunScript(data)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}

if deployDir == "" {
Expand Down Expand Up @@ -550,11 +550,11 @@ func (im *Importer) ImportFromAnsibleDir() (clusterName string, meta *spec.Metad
runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_grafana.sh")
data, err := im.fetchFile(srv.Host, srv.SSHPort, runFileName)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}
_, flags, err := parseRunScript(data)
if err != nil {
return "", nil, errors.AddStack(err)
return "", nil, err
}

for k, v := range flags {
Expand Down
12 changes: 6 additions & 6 deletions components/dm/command/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ func newImportCmd() *cobra.Command {
Short: "Import an exist DM 1.0 cluster from dm-ansible and re-deploy 2.0 version",
RunE: func(cmd *cobra.Command, args []string) error {
if err := supportVersion(clusterVersion); err != nil {
return errors.AddStack(err)
return err
}

importer, err := ansible.NewImporter(ansibleDir, inventoryFileName, gOpt.SSHType, gOpt.SSHTimeout)
if err != nil {
return errors.AddStack(err)
return err
}

clusterName, meta, err := importer.ImportFromAnsibleDir()
if err != nil {
return errors.AddStack(err)
return err
}

if rename != "" {
Expand All @@ -58,7 +58,7 @@ func newImportCmd() *cobra.Command {

err = importer.ScpSourceToMaster(meta.Topology)
if err != nil {
return errors.AddStack(err)
return err
}

data, err := yaml.Marshal(meta.Topology)
Expand Down Expand Up @@ -86,7 +86,7 @@ func newImportCmd() *cobra.Command {
clusterName,
))
if err != nil {
return errors.AddStack(err)
return err
}
}

Expand All @@ -104,7 +104,7 @@ func newImportCmd() *cobra.Command {
)

if err != nil {
return errors.AddStack(err)
return err
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions components/dm/command/scale_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ func ScaleInDMCluster(
name := instance.(*dm.MasterInstance).Name
err := dmMasterClient.OfflineMaster(name, nil)
if err != nil {
return errors.AddStack(err)
return err
}
case dm.ComponentDMWorker:
name := instance.(*dm.WorkerInstance).Name
err := dmMasterClient.OfflineWorker(name, nil)
if err != nil {
return errors.AddStack(err)
return err
}
}

Expand Down
6 changes: 3 additions & 3 deletions components/playground/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func newDisplay() *cobra.Command {
func scaleIn(pids []int) error {
port, err := targetTag()
if err != nil {
return errors.AddStack(err)
return err
}

var cmds []Command
Expand All @@ -176,7 +176,7 @@ func scaleIn(pids []int) error {
func scaleOut(args []string, opt *bootOptions) (num int, err error) {
port, err := targetTag()
if err != nil {
return 0, errors.AddStack(err)
return 0, err
}

cmds := buildCommands(ScaleOutCommandType, opt)
Expand All @@ -191,7 +191,7 @@ func scaleOut(args []string, opt *bootOptions) (num int, err error) {
func display(args []string) error {
port, err := targetTag()
if err != nil {
return errors.AddStack(err)
return err
}
c := Command{
CommandType: DisplayCommandType,
Expand Down
16 changes: 8 additions & 8 deletions components/playground/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func newGrafana(version string, host string) *grafana {
func writeDatasourceConfig(fname string, clusterName string, p8sURL string) error {
err := makeSureDir(fname)
if err != nil {
return errors.AddStack(err)
return err
}

tpl := `apiVersion: 1
Expand Down Expand Up @@ -100,7 +100,7 @@ func replaceDatasource(dashboardDir string, datasourceName string) error {

data, err := ioutil.ReadFile(path)
if err != nil {
return err
return errors.AddStack(err)
}

s := string(data)
Expand All @@ -113,7 +113,7 @@ func replaceDatasource(dashboardDir string, datasourceName string) error {
})

if err != nil {
return errors.AddStack(err)
return err
}

return nil
Expand All @@ -122,7 +122,7 @@ func replaceDatasource(dashboardDir string, datasourceName string) error {
func writeDashboardConfig(fname string, clusterName string, dir string) error {
err := makeSureDir(fname)
if err != nil {
return errors.AddStack(err)
return err
}

tpl := `apiVersion: 1
Expand Down Expand Up @@ -157,19 +157,19 @@ var clusterName string = "playground"
func (g *grafana) start(ctx context.Context, dir string, p8sURL string) (err error) {
g.port, err = utils.GetFreePort(g.host, 3000)
if err != nil {
return errors.AddStack(err)
return err
}

fname := filepath.Join(dir, "conf", "provisioning", "dashboards", "dashboard.yml")
err = writeDashboardConfig(fname, clusterName, filepath.Join(dir, "dashboards"))
if err != nil {
return errors.AddStack(err)
return err
}

fname = filepath.Join(dir, "conf", "provisioning", "datasources", "datasource.yml")
err = writeDatasourceConfig(fname, clusterName, p8sURL)
if err != nil {
return errors.AddStack(err)
return err
}

tpl := `
Expand Down Expand Up @@ -214,7 +214,7 @@ http_port = %d
}
cmd, err := tiupexec.PrepareCommand(params)
if err != nil {
return errors.AddStack(err)
return err
}
cmd.Stdout = nil
cmd.Stderr = nil
Expand Down
8 changes: 4 additions & 4 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ Examples:

port, err := utils.GetFreePort("0.0.0.0", 9527)
if err != nil {
return errors.AddStack(err)
return err
}
err = dumpPort(filepath.Join(dataDir, "port"), port)
p := NewPlayground(dataDir, port)
if err != nil {
return errors.AddStack(err)
return err
}

env, err := environment.InitEnv(repository.Options{})
if err != nil {
return errors.AddStack(err)
return err
}
environment.SetGlobalEnv(env)

Expand Down Expand Up @@ -189,7 +189,7 @@ Examples:

waitErr := p.wait()
if waitErr != nil {
return errors.AddStack(waitErr)
return waitErr
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion components/playground/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func newMonitor(ctx context.Context, version string, host, dir string) (*monitor

port, err := utils.GetFreePort(host, 9090)
if err != nil {
return nil, errors.AddStack(err)
return nil, err
}
addr := fmt.Sprintf("%s:%d", host, port)

Expand Down
Loading