From c4dd09b56a88292d2fae75ed1aa6736ecedfff0a Mon Sep 17 00:00:00 2001 From: seiya <20365512+seiyab@users.noreply.github.com> Date: Thu, 15 Oct 2026 13:08:59 +0000 Subject: [PATCH 1/7] test: expose swallowed similar question lookup error Co-Authored-By: codex --- .../service/content/question_service_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 internal/service/content/question_service_test.go diff --git a/internal/service/content/question_service_test.go b/internal/service/content/question_service_test.go new file mode 100644 index 000000000..d688c48f5 --- /dev/null +++ b/internal/service/content/question_service_test.go @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package content + +import ( + "context" + "errors" + "testing" + + "github.com/apache/answer/internal/entity" + questioncommon "github.com/apache/answer/internal/service/question_common" +) + +type similarQuestionErrorRepo struct { + questioncommon.QuestionRepo + err error +} + +func (r *similarQuestionErrorRepo) GetQuestion(context.Context, string) (*entity.Question, bool, error) { + return nil, false, r.err +} + +func TestSimilarQuestionPropagatesInfoError(t *testing.T) { + wantErr := errors.New("question lookup failed") + repo := &similarQuestionErrorRepo{err: wantErr} + service := &QuestionService{ + questioncommon: questioncommon.NewQuestionCommon( + repo, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, + ), + } + + _, _, err := service.SimilarQuestion(context.Background(), "1", "viewer") + if !errors.Is(err, wantErr) { + t.Fatalf("SimilarQuestion() error = %v, want %v", err, wantErr) + } +} From d51ea312aa0b0b183e74651c79b218d5688a0f5c Mon Sep 17 00:00:00 2001 From: seiya <20365512+seiyab@users.noreply.github.com> Date: Thu, 15 Oct 2026 13:09:51 +0000 Subject: [PATCH 2/7] return error on Info() fail --- internal/service/content/question_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/content/question_service.go b/internal/service/content/question_service.go index ced0e0109..c04baa289 100644 --- a/internal/service/content/question_service.go +++ b/internal/service/content/question_service.go @@ -1466,7 +1466,7 @@ func canViewSimilarQuestion(question *entity.Question, userID string, per schema func (qs *QuestionService) SimilarQuestion(ctx context.Context, questionID string, loginUserID string) ([]*schema.QuestionPageResp, int64, error) { question, err := qs.questioncommon.Info(ctx, questionID, loginUserID) if err != nil { - return nil, 0, nil + return nil, 0, err } tagNames := make([]string, 0, len(question.Tags)) for _, tag := range question.Tags { From 304ff973bb91c1db3622817fe2ac88eed5c5c927 Mon Sep 17 00:00:00 2001 From: seiya <20365512+seiyab@users.noreply.github.com> Date: Thu, 15 Oct 2026 13:11:49 +0000 Subject: [PATCH 3/7] test: expose swallowed revision lookup error Co-Authored-By: codex --- .../service/content/revision_service_test.go | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 internal/service/content/revision_service_test.go diff --git a/internal/service/content/revision_service_test.go b/internal/service/content/revision_service_test.go new file mode 100644 index 000000000..9545b583b --- /dev/null +++ b/internal/service/content/revision_service_test.go @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package content + +import ( + "context" + "errors" + "testing" + + "github.com/apache/answer/internal/entity" + "github.com/apache/answer/internal/schema" + "github.com/apache/answer/internal/service/revision" +) + +type checkCanUpdateRevisionErrorRepo struct { + revision.RevisionRepo + err error +} + +func (r *checkCanUpdateRevisionErrorRepo) ExistUnreviewedByObjectID(context.Context, string) (*entity.Revision, bool, error) { + return nil, false, r.err +} + +func TestCheckCanUpdateRevisionPropagatesLookupError(t *testing.T) { + wantErr := errors.New("revision lookup failed") + service := &RevisionService{ + revisionRepo: &checkCanUpdateRevisionErrorRepo{err: wantErr}, + } + + _, err := service.CheckCanUpdateRevision(context.Background(), &schema.CheckCanQuestionUpdate{ID: "1"}) + if !errors.Is(err, wantErr) { + t.Fatalf("CheckCanUpdateRevision() error = %v, want %v", err, wantErr) + } +} From adeb2150ab597d6fcb9650313a1738b254c2f5e5 Mon Sep 17 00:00:00 2001 From: seiya <20365512+seiyab@users.noreply.github.com> Date: Thu, 15 Oct 2026 13:12:13 +0000 Subject: [PATCH 4/7] return error on ExistUnereviewedByObjectID() fail --- internal/service/content/revision_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/content/revision_service.go b/internal/service/content/revision_service.go index b932ba8b7..64e5fe9d1 100644 --- a/internal/service/content/revision_service.go +++ b/internal/service/content/revision_service.go @@ -508,7 +508,7 @@ func (rs *RevisionService) CheckCanUpdateRevision(ctx context.Context, req *sche resp *schema.ErrTypeData, err error) { _, exist, err := rs.revisionRepo.ExistUnreviewedByObjectID(ctx, req.ID) if err != nil { - return nil, nil + return nil, err } if exist { return &schema.ErrTypeToast, errors.BadRequest(reason.RevisionReviewUnderway) From 01b135a03d6db04154bb5bc20f4cc376a74416f5 Mon Sep 17 00:00:00 2001 From: seiya <20365512+seiyab@users.noreply.github.com> Date: Thu, 15 Oct 2026 13:14:56 +0000 Subject: [PATCH 5/7] return error on json.Marshal() fail (never happens) --- internal/repo/captcha/captcha.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/repo/captcha/captcha.go b/internal/repo/captcha/captcha.go index f8195c1ae..800a0fd1f 100644 --- a/internal/repo/captcha/captcha.go +++ b/internal/repo/captcha/captcha.go @@ -53,7 +53,7 @@ func (cr *captchaRepo) SetActionType(ctx context.Context, unit, actionType, conf value.Num = amount valueStr, err := json.Marshal(value) if err != nil { - return nil + return err } err = cr.data.Cache.SetString(ctx, cacheKey, string(valueStr), 6*time.Minute) if err != nil { From a88eb8442d1d218805c0b92e57a4a8dd2e5a16d0 Mon Sep 17 00:00:00 2001 From: seiya <20365512+seiyab@users.noreply.github.com> Date: Thu, 15 Oct 2026 13:15:54 +0000 Subject: [PATCH 6/7] Revert "test: expose swallowed revision lookup error" This reverts commit 304ff973bb91c1db3622817fe2ac88eed5c5c927. --- .../service/content/revision_service_test.go | 51 ------------------- 1 file changed, 51 deletions(-) delete mode 100644 internal/service/content/revision_service_test.go diff --git a/internal/service/content/revision_service_test.go b/internal/service/content/revision_service_test.go deleted file mode 100644 index 9545b583b..000000000 --- a/internal/service/content/revision_service_test.go +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package content - -import ( - "context" - "errors" - "testing" - - "github.com/apache/answer/internal/entity" - "github.com/apache/answer/internal/schema" - "github.com/apache/answer/internal/service/revision" -) - -type checkCanUpdateRevisionErrorRepo struct { - revision.RevisionRepo - err error -} - -func (r *checkCanUpdateRevisionErrorRepo) ExistUnreviewedByObjectID(context.Context, string) (*entity.Revision, bool, error) { - return nil, false, r.err -} - -func TestCheckCanUpdateRevisionPropagatesLookupError(t *testing.T) { - wantErr := errors.New("revision lookup failed") - service := &RevisionService{ - revisionRepo: &checkCanUpdateRevisionErrorRepo{err: wantErr}, - } - - _, err := service.CheckCanUpdateRevision(context.Background(), &schema.CheckCanQuestionUpdate{ID: "1"}) - if !errors.Is(err, wantErr) { - t.Fatalf("CheckCanUpdateRevision() error = %v, want %v", err, wantErr) - } -} From 71c252416f8fd1a6b468b882a2aa6c5f42cfe137 Mon Sep 17 00:00:00 2001 From: seiya <20365512+seiyab@users.noreply.github.com> Date: Thu, 15 Oct 2026 13:15:56 +0000 Subject: [PATCH 7/7] Revert "test: expose swallowed similar question lookup error" This reverts commit c4dd09b56a88292d2fae75ed1aa6736ecedfff0a. --- .../service/content/question_service_test.go | 53 ------------------- 1 file changed, 53 deletions(-) delete mode 100644 internal/service/content/question_service_test.go diff --git a/internal/service/content/question_service_test.go b/internal/service/content/question_service_test.go deleted file mode 100644 index d688c48f5..000000000 --- a/internal/service/content/question_service_test.go +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package content - -import ( - "context" - "errors" - "testing" - - "github.com/apache/answer/internal/entity" - questioncommon "github.com/apache/answer/internal/service/question_common" -) - -type similarQuestionErrorRepo struct { - questioncommon.QuestionRepo - err error -} - -func (r *similarQuestionErrorRepo) GetQuestion(context.Context, string) (*entity.Question, bool, error) { - return nil, false, r.err -} - -func TestSimilarQuestionPropagatesInfoError(t *testing.T) { - wantErr := errors.New("question lookup failed") - repo := &similarQuestionErrorRepo{err: wantErr} - service := &QuestionService{ - questioncommon: questioncommon.NewQuestionCommon( - repo, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - ), - } - - _, _, err := service.SimilarQuestion(context.Background(), "1", "viewer") - if !errors.Is(err, wantErr) { - t.Fatalf("SimilarQuestion() error = %v, want %v", err, wantErr) - } -}