From 4f6fb494cb282ccbb38fe6875d214ed33da9d37d Mon Sep 17 00:00:00 2001 From: Marco Ardizzone Date: Mon, 22 Sep 2025 10:28:57 +0200 Subject: [PATCH] Add UnexpectedQueryTypeError --- backend/v3/domain/errors.go | 16 ++++++++++++ backend/v3/domain/errors_test.go | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 backend/v3/domain/errors_test.go diff --git a/backend/v3/domain/errors.go b/backend/v3/domain/errors.go index 3dd9129e3ae..29b9587fe5f 100644 --- a/backend/v3/domain/errors.go +++ b/backend/v3/domain/errors.go @@ -57,3 +57,19 @@ func NewOrgNameNotChangedError(errID string) error { func (err *OrgNameNotChangedError) Error() string { return fmt.Sprintf("ID=%s Message=organization name has not changed", err.ID) } + +type UnexpectedQueryTypeError[T any] struct { + ID string + assertedType T +} + +func NewUnexpectedQueryTypeError[T any](errID string, assertedType T) error { + return &UnexpectedQueryTypeError[T]{ + ID: errID, + assertedType: assertedType, + } +} + +func (u *UnexpectedQueryTypeError[T]) Error() string { + return fmt.Sprintf("ID=%s Message=unexpected query type '%T'", u.ID, u.assertedType) +} diff --git a/backend/v3/domain/errors_test.go b/backend/v3/domain/errors_test.go new file mode 100644 index 00000000000..c314576ec90 --- /dev/null +++ b/backend/v3/domain/errors_test.go @@ -0,0 +1,42 @@ +package domain + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestUnexpectedQueryTypeError_Error(t *testing.T) { + tests := []struct { + name string + id string + typeVal any + expected string + }{ + { + name: "string type", + id: "id1", + typeVal: "test", + expected: "ID=id1 Message=unexpected query type 'string'", + }, + { + name: "int type", + id: "id2", + typeVal: 42, + expected: "ID=id2 Message=unexpected query type 'int'", + }, + { + name: "struct type", + id: "id3", + typeVal: struct{}{}, + expected: "ID=id3 Message=unexpected query type 'struct {}'", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := NewUnexpectedQueryTypeError(tt.id, tt.typeVal) + assert.Equal(t, tt.expected, err.Error()) + }) + } +}