Skip to content

fix(knowledge): return 404 when a knowledge tag is missing - #6222

Open
Yuaneen wants to merge 1 commit into
Tencent:mainfrom
Yuaneen:fix/tag-not-found-404
Open

Yuaneen wants to merge 1 commit into
Tencent:mainfrom
Yuaneen:fix/tag-not-found-404

Conversation

@Yuaneen

@Yuaneen Yuaneen commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

PUT /knowledge-bases/{id}/tags/{tag_id} and DELETE /knowledge-bases/{id}/tags/{tag_id} answered 500 Internal server error when the tag id did not exist, for example after another admin deleted the tag or from a stale tag list.

Both service methods returned the raw gorm.ErrRecordNotFound from repo.GetByID, so the handlers could not classify the miss. Map that error to errors.NewNotFoundError("标签不存在") in UpdateTag and DeleteTag; any other storage error still surfaces as 500.

DELETE /mcp-services/{id} was fixed the same way in #6208.

Type of Change

  • 🐛 Bug fix
  • 🧪 Test

Related Issue

None.

Testing

  • New handler regressions exercise the real SQLite repository, service and error middleware:
    • TestTagMissingRegistrationReturnsNotFound: PUT/DELETE with an unknown tag id return 404 and no Internal server error.
    • TestTagLookupFailureStaysInternalError: after closing the DB, both still return 500 without echoing database is closed.
  • Before the fix TestTagMissingRegistrationReturnsNotFound failed with expected: 404, actual: 500; both pass after the fix.
  • go test ./internal/handler -run 'TestTag' -count=1 -> ok
  • go build ./internal/application/service ./internal/handler -> ok
  • gofmt -l on the changed files -> no output
  • git diff --check 71c32af...HEAD -> passes

The full root-module go test ./... is covered by CI (the local environment cannot link the prebuilt DuckDB archives). golangci-lint is not installed in this environment.

Codex assisted with the implementation and test preparation; I reviewed the diff and ran the focused checks above.

Checklist

  • git diff --check passes for the branch
  • Changed source files are formatted
  • Targeted tests for the changed packages pass
  • golangci-lint (passes in CI in 2m42s)
  • Full go test ./... (covered by the CI "Format, vet, test, and build" job, 19m11s, pass)

UpdateTag and DeleteTag returned the raw gorm.ErrRecordNotFound when the tag
id did not exist, so the handlers answered 500 Internal server error although
a missing tag is a client-visible 404.

Map the record-not-found error to errors.NewNotFoundError in both service
methods; other storage errors still surface as 500.
@Yuaneen
Yuaneen marked this pull request as ready for review November 30, 2026 09:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant