fix: add non-JSON response handling in HttpProvider and empty content validation#11
Open
knqiufan wants to merge 1 commit intoob-labs:mainfrom
Open
Conversation
… validation - HttpProvider.request(): check Content-Type before parsing, catch JSON parse errors, and return meaningful PowerMemAPIError with status code and body excerpt instead of raw SyntaxError - NativeProvider.add(): reject empty/whitespace-only content with PowerMemError (code MEMORY_VALIDATION_ERROR) - NativeProvider.update(): reject empty content and use PowerMemError (code NOT_FOUND) instead of generic Error for missing memory - Memory facade: add fast-fail validation in add() and update() - Add HttpProvider unit tests (9 cases) and empty content validation regression tests (7 cases) Port parity with Python powermem error handling patterns: - rerank/generic.py: try json(), fallback to response.text - memory.py: not content or not content.strip() guards Made-with: Cursor
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
HttpProvider.request()calledres.json()without safety checks; when the server returned HTML (e.g. 502 Bad Gateway) or plain text, callers received a rawSyntaxErrorinstead of a meaningful API error. Now checksContent-Typeheader first, catches JSON parse failures, and throwsPowerMemAPIErrorwith status code and truncated response body (max 200 chars). Matches Python pattern inrerank/generic.py(try json() → except ValueError → response.text).add({content: ''})andupdate(id, {content: ' '})silently generated empty memories, wasting storage and embedding API calls. Now validates at multiple layers (NativeProvider + Memory facade) using!content || !content.trim(), matching Python's defensivenot content or not content.strip()guards inmemory.py. Also replacesthrow new Errorwiththrow new PowerMemError('...', 'NOT_FOUND')inupdate().Changed files
src/core/http-provider.tssrc/core/native-provider.tsvalidateContent(), validate inadd()/update(), usePowerMemErrorsrc/core/memory.tsadd()/update()tests/unit/core/http-provider.test.tstests/regression/edge-cases.test.tsTest plan
success=false, connection error, 404 handling, body truncation