fix(cluster-2): error contract unification (C1/M10/M11/M12)
- http: handleError now recognizes domain.ErrNotFound in addition to the common errors.ErrNotFound sentinel, so repo-not-found maps to 404 instead of 500 (the two packages use distinct error types) - sqlite_course_repository: propagate listCount errors instead of logging and swallowing them, which left callers with a silent Count=0 - synchandler: collect course/organization insert failures into a function-scoped error via errors.Join and return it; previously the loop-local err was overwritten and the handler always returned nil, hiding all insert failures
This commit is contained in:
@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
"git.loyso.art/frx/kurious/internal/common/nullable"
|
||||
"git.loyso.art/frx/kurious/internal/common/xcontext"
|
||||
"git.loyso.art/frx/kurious/internal/common/xslices"
|
||||
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
||||
|
||||
@ -112,7 +111,7 @@ func (r *sqliteCourseRepository) List(
|
||||
|
||||
result.Count, err = r.listCount(ctx, params)
|
||||
if err != nil {
|
||||
xcontext.LogWithWarnError(ctx, r.log, err, "unable to list count")
|
||||
return result, fmt.Errorf("listing count: %w", err)
|
||||
}
|
||||
|
||||
span.SetAttributes(
|
||||
|
||||
@ -85,6 +85,7 @@ func (h *syncSravniHandler) Handle(ctx context.Context) (err error) {
|
||||
courses := make([]sravni.Course, 0, 1024)
|
||||
buffer := make([]sravni.Course, 0, 512)
|
||||
organizations := make([]sravni.Organization, 0, 256)
|
||||
var insertErr error
|
||||
for _, learningType := range learningTypes.Fields {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@ -174,22 +175,22 @@ func (h *syncSravniHandler) Handle(ctx context.Context) (err error) {
|
||||
|
||||
var insertCourseSuccess bool
|
||||
if len(courses) > 0 {
|
||||
err = h.insertCourses(lctx, courses)
|
||||
if err != nil {
|
||||
xcontext.LogWithError(lctx, h.log, err, "unable to insert courses")
|
||||
if cerr := h.insertCourses(lctx, courses); cerr != nil {
|
||||
xcontext.LogWithError(lctx, h.log, cerr, "unable to insert courses")
|
||||
insertErr = errors.Join(insertErr, cerr)
|
||||
} else {
|
||||
insertCourseSuccess = true
|
||||
}
|
||||
|
||||
insertCourseSuccess = err == nil
|
||||
}
|
||||
|
||||
var insertOrgsSuccess bool
|
||||
if len(organizations) > 0 {
|
||||
err = h.insertOrganizations(lctx, organizations)
|
||||
if err != nil {
|
||||
xcontext.LogWithError(lctx, h.log, err, "unable to insert courses")
|
||||
if oerr := h.insertOrganizations(lctx, organizations); oerr != nil {
|
||||
xcontext.LogWithError(lctx, h.log, oerr, "unable to insert organizations")
|
||||
insertErr = errors.Join(insertErr, oerr)
|
||||
} else {
|
||||
insertOrgsSuccess = true
|
||||
}
|
||||
|
||||
insertOrgsSuccess = err == nil
|
||||
}
|
||||
|
||||
elapsed = time.Since(start) - elapsed
|
||||
@ -205,7 +206,7 @@ func (h *syncSravniHandler) Handle(ctx context.Context) (err error) {
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
return insertErr
|
||||
}
|
||||
|
||||
func (h *syncSravniHandler) loadEducationalProducts(ctx context.Context, learningType, courseThematic string, buf []sravni.Course) ([]sravni.Course, map[string]sravni.Organization, error) {
|
||||
|
||||
@ -9,6 +9,7 @@ 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"
|
||||
|
||||
@ -49,7 +50,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):
|
||||
case stderrors.Is(err, errors.ErrNotFound), stderrors.Is(err, domain.ErrNotFound):
|
||||
errorString = err.Error()
|
||||
code = http.StatusNotFound
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user