From 14ce7f80e2086d13bbf39ebab7267a64d546e040 Mon Sep 17 00:00:00 2001 From: Shivanshu Raj Shrivastava Date: Tue, 29 Apr 2025 18:35:02 +0530 Subject: [PATCH] chore: fix error handling Signed-off-by: Shivanshu Raj Shrivastava --- pkg/modules/tracefunnel/impltracefunnel/store.go | 11 ++--------- pkg/types/tracefunnel/tracefunnel.go | 5 +++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/modules/tracefunnel/impltracefunnel/store.go b/pkg/modules/tracefunnel/impltracefunnel/store.go index b62d702874..fc995f568e 100644 --- a/pkg/modules/tracefunnel/impltracefunnel/store.go +++ b/pkg/modules/tracefunnel/impltracefunnel/store.go @@ -3,7 +3,6 @@ package impltracefunnel import ( "context" "fmt" - "strings" "time" "github.com/SigNoz/signoz/pkg/sqlstore" @@ -43,10 +42,7 @@ func (store *store) Create(ctx context.Context, funnel *traceFunnels.Funnel) err Model(funnel). Exec(ctx) if err != nil { - if strings.Contains(err.Error(), "idx_trace_funnel_org_id_name") { - return fmt.Errorf("a funnel with name '%s' already exists in this organization", funnel.Name) - } - return fmt.Errorf("failed to create funnel: %v", err) + return store.sqlstore.WrapAlreadyExistsErrf(err, traceFunnels.ErrFunnelAlreadyExists, "a funnel with name '%s' already exists in this organization", funnel.Name) } return nil @@ -81,10 +77,7 @@ func (store *store) Update(ctx context.Context, funnel *traceFunnels.Funnel) err WherePK(). Exec(ctx) if err != nil { - if strings.Contains(err.Error(), "idx_trace_funnel_org_id_name") { - return fmt.Errorf("a funnel with name '%s' already exists in this organization", funnel.Name) - } - return fmt.Errorf("failed to update funnel: %v", err) + return store.sqlstore.WrapAlreadyExistsErrf(err, traceFunnels.ErrFunnelAlreadyExists, "a funnel with name '%s' already exists in this organization", funnel.Name) } return nil } diff --git a/pkg/types/tracefunnel/tracefunnel.go b/pkg/types/tracefunnel/tracefunnel.go index d1ffc81c20..8ffdb6074b 100644 --- a/pkg/types/tracefunnel/tracefunnel.go +++ b/pkg/types/tracefunnel/tracefunnel.go @@ -1,12 +1,17 @@ package tracefunnel import ( + "github.com/SigNoz/signoz/pkg/errors" v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3" "github.com/SigNoz/signoz/pkg/types" "github.com/SigNoz/signoz/pkg/valuer" "github.com/uptrace/bun" ) +var ( + ErrFunnelAlreadyExists = errors.MustNewCode("funnel_already_exists") +) + // BaseMetadata metadata for funnels type BaseMetadata struct { types.Identifiable // funnel id