Skip to content

Commit

Permalink
add errors and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanmetin committed Sep 6, 2023
1 parent 2f281d6 commit f79befd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions base/commands/migration/start_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"time"

clcerrors "github.com/hazelcast/hazelcast-commandline-client/errors"
Expand Down Expand Up @@ -127,13 +128,16 @@ func (st *Stages) startStage(ctx context.Context, ec plug.ExecContext) func(stag
}
ec.PrintlnUnnecessary(msg.Message)
ec.PrintlnUnnecessary(ms.Report)
for _, l := range ms.Logs {
ec.Logger().Info(l)
}
switch ms.Status {
case StatusComplete:
return nil
case statusCanceled:
return clcerrors.ErrUserCancelled
case StatusFailed:
return errors.New("migration failed")
return fmt.Errorf("migration failed with following error(s): %s", strings.Join(ms.Errors, "\n"))
}
} else {
ec.PrintlnUnnecessary(msg.Message)
Expand All @@ -155,13 +159,16 @@ func (st *Stages) migrateStage(ctx context.Context, ec plug.ExecContext) func(st
}
ec.PrintlnUnnecessary(msg.Message)
ec.PrintlnUnnecessary(ms.Report)
for _, l := range ms.Logs {
ec.Logger().Info(l)
}
switch ms.Status {
case StatusComplete:
return nil
case statusCanceled:
return clcerrors.ErrUserCancelled
case StatusFailed:
return errors.New("migration failed")
return fmt.Errorf("migration failed with following error(s): %s", strings.Join(ms.Errors, "\n"))
}
} else {
ec.PrintlnUnnecessary(msg.Message)
Expand Down
4 changes: 3 additions & 1 deletion base/commands/migration/start_stages_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func startTest_Failure(t *testing.T) {
tcx.CLC().Execute(ctx, "start", "dmt-config", "--yes")
})
failureRunner(tcx, ctx)
for _, m := range []string{"first message", "second message", "fail status report"} {
for _, m := range []string{"first message", "second message", "error1", "error2", "fail status report"} {
tcx.AssertStdoutContains(m)
}
})
Expand All @@ -68,6 +68,7 @@ func successfulRunner(tcx it.TestContext, ctx context.Context) {
b := MustValue(json.Marshal(migration.MigrationStatus{
Status: migration.StatusComplete,
Report: "status report",
Logs: []string{"log1", "log2"},
}))
Must(statusMap.Set(ctx, migration.StatusMapEntryName, serialization.JSON(b)))
Must(topic.Publish(ctx, migration.UpdateMessage{Status: migration.StatusComplete, Message: "last message"}))
Expand All @@ -83,6 +84,7 @@ func failureRunner(tcx it.TestContext, ctx context.Context) {
b := MustValue(json.Marshal(migration.MigrationStatus{
Status: migration.StatusFailed,
Report: "fail status report",
Errors: []string{"error1", "error2"},
}))
Must(statusMap.Set(ctx, migration.StatusMapEntryName, serialization.JSON(b)))
Must(topic.Publish(ctx, migration.UpdateMessage{Status: migration.StatusFailed, Message: "second message"}))
Expand Down

0 comments on commit f79befd

Please sign in to comment.