From 8ac2d276ff6393652c6b2e8f7c7e5a2f71d29530 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Thu, 7 Dec 2023 01:04:24 -0500 Subject: [PATCH] go/vt/vtctl: fix nilness issues and error scopes (#14711) --- go/vt/vtctl/grpcvtctldserver/server.go | 10 +++------- go/vt/vtctl/workflow/server.go | 10 ++++------ go/vt/vtctl/workflow/traffic_switcher.go | 3 --- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index 2ece69876e8..8ec786322da 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -4992,9 +4992,7 @@ func (s *VtctldServer) getTopologyCell(ctx context.Context, cellPath string) (*v return nil, err } - data, _, dataErr := conn.Get(ctx, relativePath) - - if dataErr == nil { + if data, _, err := conn.Get(ctx, relativePath); err == nil { result, err := topo.DecodeContent(relativePath, data, false) if err != nil { err := vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "error decoding file content for cell %s: %v", cellPath, err) @@ -5006,15 +5004,13 @@ func (s *VtctldServer) getTopologyCell(ctx context.Context, cellPath string) (*v return &topoCell, nil } - children, childrenErr := conn.ListDir(ctx, relativePath, false /*full*/) - - if childrenErr != nil && dataErr != nil { + children, err := conn.ListDir(ctx, relativePath, false /*full*/) + if err != nil { err := vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "cell %s with path %s has no file contents and no children: %v", cell, cellPath, err) return nil, err } topoCell.Children = make([]string, len(children)) - for i, c := range children { topoCell.Children[i] = c.Name } diff --git a/go/vt/vtctl/workflow/server.go b/go/vt/vtctl/workflow/server.go index 95f1ecd42d4..ec39efa875b 100644 --- a/go/vt/vtctl/workflow/server.go +++ b/go/vt/vtctl/workflow/server.go @@ -1442,13 +1442,11 @@ func (s *Server) moveTablesCreate(ctx context.Context, req *vtctldatapb.MoveTabl return nil, err } } - if vschema != nil { - // We added to the vschema. - if err := s.ts.SaveVSchema(ctx, targetKeyspace, vschema); err != nil { - return nil, err - } - } + // We added to the vschema. + if err := s.ts.SaveVSchema(ctx, targetKeyspace, vschema); err != nil { + return nil, err + } } if err := s.ts.RebuildSrvVSchema(ctx, nil); err != nil { return nil, err diff --git a/go/vt/vtctl/workflow/traffic_switcher.go b/go/vt/vtctl/workflow/traffic_switcher.go index 35f1d1b966b..9999d46cdcc 100644 --- a/go/vt/vtctl/workflow/traffic_switcher.go +++ b/go/vt/vtctl/workflow/traffic_switcher.go @@ -380,9 +380,6 @@ func (ts *trafficSwitcher) addParticipatingTablesToKeyspace(ctx context.Context, if err := json2.Unmarshal([]byte(wrap), ks); err != nil { return err } - if err != nil { - return err - } for table, vtab := range ks.Tables { vschema.Tables[table] = vtab }