From 9088caf6001a4e4bcceb3fbdf8450875aee78f4b Mon Sep 17 00:00:00 2001 From: Aleksandr Trushkin Date: Sun, 28 Jun 2026 07:56:13 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20unify=20ErrNotFound=20=E2=80=94=20remove?= =?UTF-8?q?=20domain.ErrNotFound,=20use=20errors.ErrNotFound=20everywhere?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Responds to PR #5 review comment: consolidate on common/errors.ErrNotFound instead of having two separate error types (domain.PlainError and common/errors.SimpleError) for the same sentinel. - Remove domain.ErrNotFound and domain.PlainError type - Keep domain.ErrNotImplemented as alias to common/errors.ErrNotImplemented - Update sqlite_organization_repository to return cerrors.ErrNotFound - Update sqlite_learning_category_repository to return cerrors.ErrNotFound - Update server.go handleError to check only errors.ErrNotFound - Update test to assert errors.ErrNotFound - Remove unused domain import from server.go --- .../adapters/sqlite_learning_category_repository.go | 3 ++- .../sqlite_learning_category_repository_test.go | 3 ++- .../adapters/sqlite_organization_repository.go | 7 ++++--- internal/kurious/domain/error.go | 12 ++++-------- internal/kurious/ports/http/server.go | 3 +-- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/internal/kurious/adapters/sqlite_learning_category_repository.go b/internal/kurious/adapters/sqlite_learning_category_repository.go index b3e9572..f65e6db 100644 --- a/internal/kurious/adapters/sqlite_learning_category_repository.go +++ b/internal/kurious/adapters/sqlite_learning_category_repository.go @@ -8,6 +8,7 @@ import ( "log/slog" "strings" + cerrors "git.loyso.art/frx/kurious/internal/common/errors" "git.loyso.art/frx/kurious/internal/common/xslices" "git.loyso.art/frx/kurious/internal/kurious/domain" @@ -156,7 +157,7 @@ func (r *sqliteLearingCategoryRepository) Get(ctx context.Context, id string) (c err = r.db.GetContext(ctx, &cdb, query, id) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return domain.LearningCategory{}, domain.ErrNotFound + return domain.LearningCategory{}, cerrors.ErrNotFound } return domain.LearningCategory{}, fmt.Errorf("executing query: %w", err) } diff --git a/internal/kurious/adapters/sqlite_learning_category_repository_test.go b/internal/kurious/adapters/sqlite_learning_category_repository_test.go index 9038cc3..0e5c8c9 100644 --- a/internal/kurious/adapters/sqlite_learning_category_repository_test.go +++ b/internal/kurious/adapters/sqlite_learning_category_repository_test.go @@ -3,6 +3,7 @@ package adapters import ( "testing" + "git.loyso.art/frx/kurious/internal/common/errors" "git.loyso.art/frx/kurious/internal/common/nullable" "git.loyso.art/frx/kurious/internal/kurious/domain" @@ -75,7 +76,7 @@ func (s *sqliteLearningCategoriesRepositorySuite) TestUpsert() { const categoryID = "test-id-1" repo := s.connection.LearningCategory() gotCategory, err := repo.Get(s.ctx, categoryID) - s.ErrorIs(err, domain.ErrNotFound) + s.ErrorIs(err, errors.ErrNotFound) s.Empty(gotCategory) createdCategory := domain.LearningCategory{ diff --git a/internal/kurious/adapters/sqlite_organization_repository.go b/internal/kurious/adapters/sqlite_organization_repository.go index 3ab2e9c..68132e4 100644 --- a/internal/kurious/adapters/sqlite_organization_repository.go +++ b/internal/kurious/adapters/sqlite_organization_repository.go @@ -9,6 +9,7 @@ import ( "strings" "time" + cerrors "git.loyso.art/frx/kurious/internal/common/errors" "git.loyso.art/frx/kurious/internal/common/xslices" "git.loyso.art/frx/kurious/internal/kurious/domain" "go.opentelemetry.io/otel/attribute" @@ -228,7 +229,7 @@ func (r *sqliteOrganizationRepository) Get(ctx context.Context, params domain.Ge err = r.db.GetContext(ctx, &orgdb, query, args...) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return out, domain.ErrNotFound + return out, cerrors.ErrNotFound } return out, fmt.Errorf("executing query: %w", err) } @@ -306,14 +307,14 @@ func (r *sqliteOrganizationRepository) Delete(ctx context.Context, id string) (e result, err := r.db.ExecContext(ctx, query, id) if err != nil { if errors.Is(err, sql.ErrNoRows) { - return domain.ErrNotFound + return cerrors.ErrNotFound } return fmt.Errorf("executing query: %w", err) } affected, _ := result.RowsAffected() if affected == 0 { - return domain.ErrNotFound + return cerrors.ErrNotFound } return nil diff --git a/internal/kurious/domain/error.go b/internal/kurious/domain/error.go index ce3f41c..75fcac5 100644 --- a/internal/kurious/domain/error.go +++ b/internal/kurious/domain/error.go @@ -1,12 +1,8 @@ package domain -const ( - ErrNotFound PlainError = "not found" - ErrNotImplemented PlainError = "not implemented" +import ( + cerrors "git.loyso.art/frx/kurious/internal/common/errors" ) -type PlainError string - -func (err PlainError) Error() string { - return string(err) -} +// ErrNotImplemented is delegated to common/errors.ErrNotImplemented for consistency. +var ErrNotImplemented = cerrors.ErrNotImplemented diff --git a/internal/kurious/ports/http/server.go b/internal/kurious/ports/http/server.go index 10b5243..5b91266 100644 --- a/internal/kurious/ports/http/server.go +++ b/internal/kurious/ports/http/server.go @@ -9,7 +9,6 @@ import ( "git.loyso.art/frx/kurious/internal/common/errors" "git.loyso.art/frx/kurious/internal/common/xcontext" - "git.loyso.art/frx/kurious/internal/kurious/domain" "git.loyso.art/frx/kurious/internal/kurious/service" "git.loyso.art/frx/kurious/pkg/xdefault" @@ -50,7 +49,7 @@ func handleError(ctx context.Context, err error, w http.ResponseWriter, log *slo case stderrors.As(err, &valErr): errorString = valErr.Error() code = http.StatusBadRequest - case stderrors.Is(err, errors.ErrNotFound), stderrors.Is(err, domain.ErrNotFound): + case stderrors.Is(err, errors.ErrNotFound): errorString = err.Error() code = http.StatusNotFound default: