Skip to content

Commit

Permalink
Tweaks to how we return err info
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Dec 1, 2023
1 parent 155fd0f commit 9dba5b5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/jimmctl/cmd/migratemodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ type migrateModelSuite struct {
var _ = gc.Suite(&migrateModelSuite{})

var migrationResultRegex = `results:
- modeltag: ""
- modeltag: model-.*
error:
message: 'target prechecks failed: model with same UUID already exists (.*)'
code: ""
info: {}
migrationid: ""
- modeltag: ""
- modeltag: model-.*
error:
message: 'target prechecks failed: model with same UUID already exists (.*)'
code: ""
Expand Down
2 changes: 1 addition & 1 deletion internal/jimm/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func (j *JIMM) InitiateMigration(ctx context.Context, user *openfga.User, spec j
err = j.Database.UpdateModel(ctx, &model)
if err != nil {
zapctx.Error(ctx, "failed to update model with migration info", zap.Error(err))
return result, errors.E(op, fmt.Sprintf("migration started but failed to queue JIMM automatic update\n migration ID = %s\n", result.MigrationId), err)
return result, errors.E(op, "migration started but failed to queue JIMM automatic update", err)
}

return result, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/jimm/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (j *JIMM) InitiateInternalMigration(ctx context.Context, user *openfga.User
spec := jujuparams.MigrationSpec{ModelTag: modelTag.String(), TargetInfo: migrationTarget}
result, err := initiateMigration(ctx, j, user, spec, controllerID)
if err != nil {
return jujuparams.InitiateMigrationResult{}, errors.E(op, err)
return result, errors.E(op, err)
}
return result, nil
}
3 changes: 1 addition & 2 deletions internal/jujuapi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ func (r *controllerRoot) InitiateMigration(ctx context.Context, args jujuparams.
for i, spec := range args.Specs {
result, err := r.jimm.InitiateMigration(ctx, r.user, spec, 0)
if err != nil {
results[i].Error = mapError(errors.E(op, err))
continue
result.Error = mapError(errors.E(op, err))
}
results[i] = result
}
Expand Down
3 changes: 1 addition & 2 deletions internal/jujuapi/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ func (r *controllerRoot) MigrateModel(ctx context.Context, args apiparams.Migrat
}
result, err := r.jimm.InitiateInternalMigration(ctx, r.user, mt, arg.TargetController)
if err != nil {
results[i].Error = mapError(errors.E(op, err))
continue
result.Error = mapError(errors.E(op, err))
}
results[i] = result
}
Expand Down
7 changes: 4 additions & 3 deletions internal/jujuapi/jimm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,8 @@ func (s *jimmSuite) TestJimmModelMigration(c *gc.C) {
})
c.Assert(err, gc.IsNil)
c.Assert(res.Results, gc.HasLen, 1)
for _, item := range res.Results {
c.Assert(item.Error.Message, gc.Matches, "target prechecks failed: model with same UUID already exists .*")
}
item := res.Results[0]
c.Assert(item.ModelTag, gc.Equals, mt.String())
c.Assert(item.MigrationId, gc.Equals, "")
c.Assert(item.Error.Message, gc.Matches, "target prechecks failed: model with same UUID already exists .*")
}

0 comments on commit 9dba5b5

Please sign in to comment.