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

[CLC-442]: Fix defers #436

Merged
merged 3 commits into from
Nov 15, 2023
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
10 changes: 6 additions & 4 deletions base/commands/migration/migration_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ In order to cancel the migration, use the 'cancel' command.
return err
}
defer func() {
maybePrintWarnings(ctx, ec, sts.ci, mID)
finalizeErr := finalizeMigration(ctx, ec, sts.ci, mID, ec.Props().GetString(flagOutputDir))
if err == nil {
err = finalizeErr
if sts.ci != nil {
maybePrintWarnings(ctx, ec, sts.ci, mID)
finalizeErr := finalizeMigration(ctx, ec, sts.ci, mID, ec.Props().GetString(flagOutputDir))
if err == nil {
err = finalizeErr
}
}
}()
sp := stage.NewFixedProvider(sts.Build(ctx, ec)...)
Expand Down
15 changes: 8 additions & 7 deletions base/commands/migration/migration_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ func (s StatusCmd) Exec(ctx context.Context, ec plug.ExecContext) (err error) {
ec.PrintlnUnnecessary("")
ec.PrintlnUnnecessary(banner)
sts := NewStatusStages()
sp := stage.NewFixedProvider(sts.Build(ctx, ec)...)
mID, err := stage.Execute(ctx, ec, any(nil), sp)
mID, err := stage.Execute(ctx, ec, "", stage.NewFixedProvider(sts.Build(ctx, ec)...))
if err != nil {
return err
}
defer func() {
maybePrintWarnings(ctx, ec, sts.ci, mID.(string))
finalizeErr := finalizeMigration(ctx, ec, sts.ci, mID.(string), ec.Props().GetString(flagOutputDir))
if err == nil {
err = finalizeErr
if sts.ci != nil {
maybePrintWarnings(ctx, ec, sts.ci, mID)
finalizeErr := finalizeMigration(ctx, ec, sts.ci, mID, ec.Props().GetString(flagOutputDir))
if err == nil {
err = finalizeErr
}
}
}()
mStages, err := createMigrationStages(ctx, ec, sts.ci, mID.(string))
mStages, err := createMigrationStages(ctx, ec, sts.ci, mID)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions base/commands/migration/status_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func NewStatusStages() *StatusStages {
return &StatusStages{}
}

func (st *StatusStages) Build(ctx context.Context, ec plug.ExecContext) []stage.Stage[any] {
return []stage.Stage[any]{
func (st *StatusStages) Build(ctx context.Context, ec plug.ExecContext) []stage.Stage[string] {
return []stage.Stage[string]{
{
ProgressMsg: "Connecting to the migration cluster",
SuccessMsg: "Connected to the migration cluster",
Expand All @@ -35,22 +35,22 @@ func (st *StatusStages) Build(ctx context.Context, ec plug.ExecContext) []stage.
}
}

func (st *StatusStages) connectStage(ec plug.ExecContext) func(context.Context, stage.Statuser[any]) (any, error) {
return func(ctx context.Context, status stage.Statuser[any]) (any, error) {
func (st *StatusStages) connectStage(ec plug.ExecContext) func(context.Context, stage.Statuser[string]) (string, error) {
return func(ctx context.Context, status stage.Statuser[string]) (string, error) {
var err error
st.ci, err = ec.ClientInternal(ctx)
if err != nil {
return nil, err
return "", err
}
return nil, nil
return "", nil
}
}

func (st *StatusStages) findMigrationInProgress(ec plug.ExecContext) func(context.Context, stage.Statuser[any]) (any, error) {
return func(ctx context.Context, status stage.Statuser[any]) (any, error) {
func (st *StatusStages) findMigrationInProgress(ec plug.ExecContext) func(context.Context, stage.Statuser[string]) (string, error) {
return func(ctx context.Context, status stage.Statuser[string]) (string, error) {
m, err := findMigrationInProgress(ctx, st.ci)
if err != nil {
return nil, err
return "", err
}
return m.MigrationID, err
}
Expand Down
Loading