From 712e0040d4dc0c134f6811fd6527f68c37881a74 Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Fri, 16 Aug 2024 11:06:41 -0400 Subject: [PATCH] Improve error handling Signed-off-by: Matt Lord --- go/vt/vtctl/workflow/server.go | 2 +- go/vt/vtctl/workflow/traffic_switcher.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/go/vt/vtctl/workflow/server.go b/go/vt/vtctl/workflow/server.go index 9bd3ea2796c..e1b9859e897 100644 --- a/go/vt/vtctl/workflow/server.go +++ b/go/vt/vtctl/workflow/server.go @@ -3501,7 +3501,7 @@ func (s *Server) switchWrites(ctx context.Context, req *vtctldatapb.WorkflowSwit // intra-keyspace materializations that write on the source), and we know for certain // that any in progress writes are done. if err := ts.gatherSourcePositions(ctx); err != nil { - return handleError("failed to get replication positions on migration sources", err) + return handleError("failed to gather replication positions on migration sources", err) } if err := confirmKeyspaceLocksHeld(); err != nil { diff --git a/go/vt/vtctl/workflow/traffic_switcher.go b/go/vt/vtctl/workflow/traffic_switcher.go index 3f29aa2a74a..34e1e4e4329 100644 --- a/go/vt/vtctl/workflow/traffic_switcher.go +++ b/go/vt/vtctl/workflow/traffic_switcher.go @@ -1016,7 +1016,7 @@ func (ts *trafficSwitcher) stopSourceWrites(ctx context.Context) error { err = ts.changeShardsAccess(ctx, ts.SourceKeyspaceName(), ts.SourceShards(), disallowWrites) } if err != nil { - ts.Logger().Warningf("Error stopping writes: %s", err) + ts.Logger().Warningf("Error stopping writes on migration sources: %v", err) return err } return nil @@ -1315,13 +1315,14 @@ func (ts *trafficSwitcher) gatherSourcePositions(ctx context.Context) error { return ts.ForAllSources(func(source *MigrationSource) error { var err error tablet := source.GetPrimary().Tablet - source.Position, err = ts.TabletManagerClient().PrimaryPosition(ctx, tablet) tabletAlias := topoproto.TabletAliasString(tablet.Alias) - ts.Logger().Infof("Position on migration source %s after having stopped writes: %s", tabletAlias, source.Position) + source.Position, err = ts.TabletManagerClient().PrimaryPosition(ctx, tablet) if err != nil { ts.Logger().Errorf("Error getting migration source position on %s: %s", tabletAlias, err) - return vterrors.Wrapf(err, "failed to get position on %s", tabletAlias) + return vterrors.Errorf(vtrpcpb.Code_INTERNAL, "failed to get position on migration source %s: %v", + tabletAlias, err) } + ts.Logger().Infof("Position on migration source %s after having stopped writes: %s", tabletAlias, source.Position) return nil }) }