fix(knowledge): answer a rejected kb path with 400 KNOWLEDGE_PATH_INVALID instead of 500 - #910
Open
Lesereingrape wants to merge 16 commits into
Open
Lesereingrape wants to merge 16 commits into
Lesereingrape wants to merge 16 commits into
Conversation
Two validators reject a caller-supplied knowledge path with ValueError:
normalize_kb_path() for a ".." segment ("invalid knowledge document
path") and ensure_folder() for a path that normalizes to empty -- ".",
"/", which pass CreateFolderBody's min_length ("invalid knowledge folder
path"). _map_knowledge_error() had no branch for either message, so both
fell through to INTERNAL_ERROR: HTTP 500, details echoing an internal
message, and a logger.exception stack trace on every request. The sibling
name check two lines above already answers 400 for the same class of input.
Map both messages to a new KNOWLEDGE_PATH_INVALID rather than reusing
KNOWLEDGE_NAME_INVALID, whose copy ("Invalid name.") points at the wrong
field when the path is what was rejected. Which paths stay invalid is
unchanged here -- only how the rejection is reported.
A new ErrorCode needs all four locale bundles per the i18n checklist in
AGENTS.md: backend errors (en/zh) plus dashboard apiErrors (en/zh).
tests/unit/i18n/test_errors.py already fails if those key sets drift.
4 of 11 tasks
…d-400 CHANGELOG.md only: keep the entries added on develop since e512f05 and place this fix's entry after them.
Contributor
Author
|
CHANGELOG 冲突已解决(本 PR 与 #912 都会在
|
…d-400 # Conflicts: # CHANGELOG.md
…d-400 # Conflicts: # CHANGELOG.md
…d-400 # Conflicts: # CHANGELOG.md
…d-400 # Conflicts: # CHANGELOG.md # tests/unit/api/test_knowledge_bases.py
…d-400 # Conflicts: # tests/unit/api/test_knowledge_bases.py
1 task
…d-400 # Conflicts: # CHANGELOG.md
…Unreleased overlap)
…d-400 # Conflicts: # CHANGELOG.md
…d-400 # Conflicts: # CHANGELOG.md
…d-400 # Conflicts: # CHANGELOG.md
…d-400 # Conflicts: # CHANGELOG.md
…d-400 # Conflicts: # CHANGELOG.md
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A knowledge path the server refuses to accept was answered as a server error. Two validators raise it and neither message was mapped:
normalize_kb_path()rejects a..segment →ValueError("invalid knowledge document path")(src/octop/infra/knowledge/relpath.py:15)KnowledgeRepo.ensure_folder()rejects a path that normalizes to empty —".","/","///"→ValueError("invalid knowledge folder path")(src/octop/infra/db/repos/knowledge.py:259)_map_knowledge_error()had branches for the name, size, limit, content-type and prerequisite rejections but none for these two, so they fell through tologger.exception(...)+INTERNAL_ERROR: HTTP 500,details.causeechoing an internal message, and a stack trace per request — while the sibling name check two lines above (:244) already answers 400 for the same class of caller input.CreateFolderBody.pathonly enforcesmin_length=1, so both spellings reach the service.Both messages now map to a new
KNOWLEDGE_PATH_INVALID(400). Deliberately not reusingKNOWLEDGE_NAME_INVALID, whose copy is"Invalid name."and would point at the wrong field. Which paths stay invalid is unchanged — only how the rejection is reported.Per the i18n checklist in
AGENTS.md§7, a newErrorCodemeans four bundles: backenderrors(en/zh) and dashboardapiErrors(en/zh).tests/unit/i18n/test_errors.py::test_dashboard_api_errors_match_backendandtest_every_error_code_has_i18n_entryalready enforce that parity, and both pass.Fixes #909
Related open work
Recently merged PR #889 (2026-09-21,
fix(knowledge): 删除文件夹时不再误删名字相近的文件夹) also touchesinfra/db/repos/knowledge.py, where these twoValueErrors are raised — but it changes which rows a folder delete matches, not how a rejection is reported. Re-read againstdevelop@e512f05b(this branch is rebased onto it)::259still raisesinvalid knowledge folder path,relpath.py:15still raisesinvalid knowledge document path, and_map_knowledge_error(knowledge_bases.py:201) still has no branch for either — it matches…document nameonly — so both still reachINTERNAL_ERRORon that head (measured:".","/","..","a/../b"→code=INTERNAL_ERROR status=500).Target branch
develop(feature / fix — default)main(release/*orhotfix/*only)Type of change
Test plan
makeis unavailable on this machine, so the.githooks/pre-commitgate (make all+dashboardbuild, perAGENTS.md§6/§10) never ran here — the commit was made without it. Its sub-targets were run individually and are quoted verbatim below.RED — the committed tests, run against a tree that has the enum and the four locale bundles but
not the router branch (
b46bb8a4+ this branch's files exceptknowledge_bases.py):Behaviour, probed against
KnowledgeRepo.ensure_folderfed to the router's own mapper (".","/","..","a/../b"— all Pydantic-valid bodies), re-measured today on pristinedevelop@e512f05bvs this branch:Final state on this branch (Windows / Python 3.12, head
2d3cbf33on top ofe512f05b;make testequivalents):tests/unit/api/test_knowledge_bases.py, following the existingtest_rename_document_maps_invalid_name/test_map_knowledge_error_*idiomsChecklist
CHANGELOG.md— one bullet at the top of### 修复under## [Unreleased], citing(#909), landed as commit2d3cbf33docs/api.mddocuments theapiErrorsmirroring mechanism, not individual codesNot tested here: no live server run, so the repro is at the mapper + repo-validation level rather than a real HTTP response; the two dashboard locale files were not passed through Prettier (no
node_moduleson this box) — both lines copy the indentation and quoting of their neighbours; CI's Linux leg was not run locally.