From a5a95094841a564f4d3c51c754bb1b7b4bbac553 Mon Sep 17 00:00:00 2001 From: Katrina Rogan Date: Mon, 11 Dec 2023 09:00:31 -0800 Subject: [PATCH] Return InvalidArgument for workflow compilation failures in CreateWorkflow (#4566) * Return InvalidArgument for workflow compilation failures in CreateWorkflow Signed-off-by: Katrina Rogan * lint Signed-off-by: Katrina Rogan --------- Signed-off-by: Katrina Rogan Co-authored-by: Dan Rammer --- flyteadmin/cmd/entrypoints/serve.go | 2 +- flyteadmin/pkg/manager/impl/workflow_manager.go | 2 +- flyteadmin/pkg/manager/impl/workflow_manager_test.go | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/flyteadmin/cmd/entrypoints/serve.go b/flyteadmin/cmd/entrypoints/serve.go index b3b575baba..7ef146a1fe 100644 --- a/flyteadmin/cmd/entrypoints/serve.go +++ b/flyteadmin/cmd/entrypoints/serve.go @@ -35,7 +35,7 @@ var serveCmd = &cobra.Command{ // register otel tracer providers for _, serviceName := range []string{otelutils.AdminGormTracer, otelutils.AdminServerTracer} { - if err := otelutils.RegisterTracerProvider(serviceName, otelutils.GetConfig()) ; err != nil { + if err := otelutils.RegisterTracerProvider(serviceName, otelutils.GetConfig()); err != nil { logger.Errorf(ctx, "Failed to create otel tracer provider. %v", err) return err } diff --git a/flyteadmin/pkg/manager/impl/workflow_manager.go b/flyteadmin/pkg/manager/impl/workflow_manager.go index 1b3b0e393e..207a471468 100644 --- a/flyteadmin/pkg/manager/impl/workflow_manager.go +++ b/flyteadmin/pkg/manager/impl/workflow_manager.go @@ -146,7 +146,7 @@ func (w *WorkflowManager) CreateWorkflow( workflowClosure, err := w.getCompiledWorkflow(ctx, finalizedRequest) if err != nil { logger.Errorf(ctx, "Failed to compile workflow with err: %v", err) - return nil, errors.NewFlyteAdminErrorf(codes.Internal, + return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "failed to compile workflow for [%+v] with err %v", request.Id, err) } err = validation.ValidateCompiledWorkflow( diff --git a/flyteadmin/pkg/manager/impl/workflow_manager_test.go b/flyteadmin/pkg/manager/impl/workflow_manager_test.go index a3788096e3..99da70a64b 100644 --- a/flyteadmin/pkg/manager/impl/workflow_manager_test.go +++ b/flyteadmin/pkg/manager/impl/workflow_manager_test.go @@ -9,6 +9,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "github.com/flyteorg/flyte/flyteadmin/pkg/common" commonMocks "github.com/flyteorg/flyte/flyteadmin/pkg/common/mocks" @@ -243,10 +244,13 @@ func TestCreateWorkflow_CompileWorkflowError(t *testing.T) { getMockWorkflowConfigProvider(), mockCompiler, getMockStorage(), storagePrefix, mockScope.NewTestScope()) request := testutils.GetWorkflowRequest() response, err := workflowManager.CreateWorkflow(context.Background(), request) + assert.Nil(t, response) + s, ok := status.FromError(err) + assert.True(t, ok) + assert.Equal(t, codes.InvalidArgument, s.Code()) assert.EqualError(t, err, fmt.Sprintf( "failed to compile workflow for [resource_type:WORKFLOW project:\"project\" domain:\"domain\" "+ "name:\"name\" version:\"version\" ] with err %v", expectedErr.Error())) - assert.Nil(t, response) } func TestCreateWorkflow_DatabaseError(t *testing.T) {