From be25b7115b432da052cedb74ffe274cc0cdebcce Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Mon, 24 Jun 2024 11:59:24 -0700 Subject: [PATCH] Add name to ExistsDifferentStructureError message Signed-off-by: Kevin Su --- flyteadmin/pkg/errors/errors.go | 4 ++-- flyteadmin/pkg/errors/errors_test.go | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/flyteadmin/pkg/errors/errors.go b/flyteadmin/pkg/errors/errors.go index 366e2a3f42..51e5ede579 100644 --- a/flyteadmin/pkg/errors/errors.go +++ b/flyteadmin/pkg/errors/errors.go @@ -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) @@ -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) diff --git a/flyteadmin/pkg/errors/errors_test.go b/flyteadmin/pkg/errors/errors_test.go index 6c97d9e911..c126f96d6d 100644 --- a/flyteadmin/pkg/errors/errors_test.go +++ b/flyteadmin/pkg/errors/errors_test.go @@ -19,7 +19,7 @@ var identifier = core.Identifier{ ResourceType: core.ResourceType_TASK, Project: "testProj", Domain: "domain", - Name: "name", + Name: "t1", Version: "ver", } @@ -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) { @@ -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, } @@ -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: -> 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]] -> \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: -> 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]] -> \n\t\t- /primary/template/nodes/0/id: foo -> bar", s.Message()) details, ok := s.Details()[0].(*admin.CreateWorkflowFailureReason) assert.True(t, ok)