Skip to content

Commit

Permalink
go/vt/vtctl: fix nilness issues and error scopes (#14711)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlayher authored Dec 7, 2023
1 parent c6a6bfe commit 8ac2d27
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
10 changes: 3 additions & 7 deletions go/vt/vtctl/grpcvtctldserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
10 changes: 4 additions & 6 deletions go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions go/vt/vtctl/workflow/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8ac2d27

Please sign in to comment.