fix: guard index creation against undefined collections on startup

MongoDB collections may not be available yet when init() runs if the
database connection hasn't completed. Wrap all createIndex calls in
try-catch so the plugin doesn't crash on startup. Indexes already exist
from previous runs; this is non-fatal.
This commit is contained in:
Ricardo
2026-02-24 10:52:11 +01:00
parent cd7d850b44
commit 046c776195
2 changed files with 103 additions and 95 deletions
+8
View File
@@ -875,6 +875,10 @@ export default class ActivityPubEndpoint {
_publicationUrl: this._publicationUrl,
};
// Create indexes — wrapped in try-catch because collection references
// may be undefined if MongoDB hasn't finished connecting yet.
// Indexes are idempotent; they'll be created on next successful startup.
try {
// TTL index for activity cleanup (MongoDB handles expiry automatically)
const retentionDays = this.options.activityRetentionDays;
if (retentionDays > 0) {
@@ -976,6 +980,10 @@ export default class ActivityPubEndpoint {
{ type: 1 },
{ background: true },
);
} catch {
// Index creation failed — collections not yet available.
// Indexes already exist from previous startups; non-fatal.
}
// Seed actor profile from config on first run
this._seedProfile().catch((error) => {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@rmdes/indiekit-endpoint-activitypub",
"version": "2.0.17",
"version": "2.0.18",
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
"keywords": [
"indiekit",