Skip to content

fix(endpoint-micropub): throw a clear error reading posts without a database - #905

Open
rmdes wants to merge 1 commit into
getindiekit:mainfrom
rmdes:fix/post-data-read-without-database
Open

fix(endpoint-micropub): throw a clear error reading posts without a database#905
rmdes wants to merge 1 commit into
getindiekit:mainfrom
rmdes:fix/post-data-read-without-database

Conversation

@rmdes

@rmdes rmdes commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Fixes #904.

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, 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 notImplemented with a message saying so.

Changes

  • packages/endpoint-micropub/lib/post-data.js — guard the collection lookup in read()
  • packages/endpoint-micropub/test/unit/post-data.js — regression test

Verification

$ NODE_ENV=test node --test packages/endpoint-micropub/test/unit/post-data.js
ℹ tests 11
ℹ pass 11
ℹ fail 0

Red/green checked: with the guard removed the new test fails (10 pass, 1 fail); restored, 11 pass.

…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.
@paulrobertlloyd paulrobertlloyd added the plugin-endpoint Endpoint plug-in label Aug 23, 2026
@paulrobertlloyd paulrobertlloyd added this to the v1.0 milestone Aug 23, 2026
const postsCollection = application?.collections?.get("posts");

if (!postsCollection) {
throw IndiekitError.notImplemented(

@paulrobertlloyd paulrobertlloyd Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

plugin-endpoint Endpoint plug-in

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleting a post without a database throws TypeError instead of a meaningful error

2 participants