fix(endpoint-micropub): throw a clear error reading posts without a database - #905
Open
rmdes wants to merge 1 commit into
Open
fix(endpoint-micropub): throw a clear error reading posts without a database#905rmdes wants to merge 1 commit into
rmdes wants to merge 1 commit into
Conversation
…atabase postData.read() looked up the posts collection with optional chaining, then called findOne() on it unguarded. With no database configured this threw a TypeError instead of a meaningful error. update(), delete() and undelete() all call read() first, so a single missing guard affected four operations. create() already guards the same lookup. MongoDB is documented as optional, and as required for reading, updating, deleting and restoring posts, so this now throws notImplemented with a message saying so.
| const postsCollection = application?.collections?.get("posts"); | ||
|
|
||
| if (!postsCollection) { | ||
| throw IndiekitError.notImplemented( |
Collaborator
There was a problem hiding this comment.
This should be a localisable string. We currently have NotImplementedError.database, which in English says:
This feature requires a database
That’s not as explicit as your message, but does cover this use case.
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.
Fixes #904.
postData.read()looked up the posts collection with optional chaining, then calledfindOne()on it unguarded. With no database configured this threw aTypeErrorinstead of a meaningful error.update(),delete()andundelete()all callread()first, so a single missing guard affected four operations.create()already guards the same lookup, which is why publishing works without a database and reading does not.MongoDB is documented as optional, and as required for reading, updating, deleting and restoring posts, so this throws
notImplementedwith a message saying so.Changes
packages/endpoint-micropub/lib/post-data.js— guard the collection lookup inread()packages/endpoint-micropub/test/unit/post-data.js— regression testVerification
Red/green checked: with the guard removed the new test fails (10 pass, 1 fail); restored, 11 pass.