Skip to content

Commit

Permalink
Add name to ExistsDifferentStructureError message
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw committed Jun 24, 2024
1 parent c10346d commit be25b71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions flyteadmin/pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func compareJsons(jsonArray1 jsondiff.Patch, jsonArray2 jsondiff.Patch) []string
}

func NewTaskExistsDifferentStructureError(ctx context.Context, request *admin.TaskCreateRequest, oldSpec *core.CompiledTask, newSpec *core.CompiledTask) FlyteAdminError {
errorMsg := "task with different structure already exists:\n"
errorMsg := fmt.Sprintf("%v task with different structure already exists:\n", request.Id.Name)
diff, _ := jsondiff.Compare(oldSpec, newSpec)
rdiff, _ := jsondiff.Compare(newSpec, oldSpec)
rs := compareJsons(diff, rdiff)
Expand All @@ -145,7 +145,7 @@ func NewTaskExistsIdenticalStructureError(ctx context.Context, request *admin.Ta
}

func NewWorkflowExistsDifferentStructureError(ctx context.Context, request *admin.WorkflowCreateRequest, oldSpec *core.CompiledWorkflowClosure, newSpec *core.CompiledWorkflowClosure) FlyteAdminError {
errorMsg := "workflow with different structure already exists:\n"
errorMsg := fmt.Sprintf("%v workflow with different structure already exists:\n", request.Id.Name)
diff, _ := jsondiff.Compare(oldSpec, newSpec)
rdiff, _ := jsondiff.Compare(newSpec, oldSpec)
rs := compareJsons(diff, rdiff)
Expand Down
14 changes: 11 additions & 3 deletions flyteadmin/pkg/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var identifier = core.Identifier{
ResourceType: core.ResourceType_TASK,
Project: "testProj",
Domain: "domain",
Name: "name",
Name: "t1",
Version: "ver",
}

Expand Down Expand Up @@ -144,7 +144,7 @@ func TestNewTaskExistsDifferentStructureError(t *testing.T) {
s, ok := status.FromError(statusErr)
assert.True(t, ok)
assert.Equal(t, codes.InvalidArgument, s.Code())
assert.Equal(t, "task with different structure already exists:\n\t\t- /template/Target/Container/resources/requests/0/value: 150m -> 250m", s.Message())
assert.Equal(t, "t1 task with different structure already exists:\n\t\t- /template/Target/Container/resources/requests/0/value: 150m -> 250m", s.Message())
}

func TestNewTaskExistsIdenticalStructureError(t *testing.T) {
Expand All @@ -160,6 +160,14 @@ func TestNewTaskExistsIdenticalStructureError(t *testing.T) {
}

func TestNewWorkflowExistsDifferentStructureError(t *testing.T) {
identifier = core.Identifier{
ResourceType: core.ResourceType_WORKFLOW,
Project: "testProj",
Domain: "domain",
Name: "hello",
Version: "ver",
}

req := &admin.WorkflowCreateRequest{
Id: &identifier,
}
Expand Down Expand Up @@ -217,7 +225,7 @@ func TestNewWorkflowExistsDifferentStructureError(t *testing.T) {
s, ok := status.FromError(statusErr)
assert.True(t, ok)
assert.Equal(t, codes.InvalidArgument, s.Code())
assert.Equal(t, "workflow with different structure already exists:\n\t\t- /primary/connections/upstream/bar: <nil> -> map[ids:[start-node]]\n\t\t- /primary/connections/upstream/end-node/ids/0: foo -> bar\n\t\t- /primary/connections/upstream/foo: map[ids:[start-node]] -> <nil>\n\t\t- /primary/template/nodes/0/id: foo -> bar", s.Message())
assert.Equal(t, "hello workflow with different structure already exists:\n\t\t- /primary/connections/upstream/bar: <nil> -> map[ids:[start-node]]\n\t\t- /primary/connections/upstream/end-node/ids/0: foo -> bar\n\t\t- /primary/connections/upstream/foo: map[ids:[start-node]] -> <nil>\n\t\t- /primary/template/nodes/0/id: foo -> bar", s.Message())

details, ok := s.Details()[0].(*admin.CreateWorkflowFailureReason)
assert.True(t, ok)
Expand Down

0 comments on commit be25b71

Please sign in to comment.