diff --git a/baker/algolia/indexChartsToAlgolia.ts b/baker/algolia/indexChartsToAlgolia.ts index 1bb60bfac9..984e5709f6 100644 --- a/baker/algolia/indexChartsToAlgolia.ts +++ b/baker/algolia/indexChartsToAlgolia.ts @@ -2,6 +2,7 @@ // set up before any errors are thrown. import "../../serverUtils/instrument.js" +import * as Sentry from "@sentry/node" import * as db from "../../db/db.js" import { ALGOLIA_INDEXING } from "../../settings/serverSettings.js" import { getAlgoliaClient } from "./configureAlgolia.js" @@ -27,9 +28,9 @@ const indexChartsToAlgolia = async () => { await index.replaceAllObjects(records) } -process.on("unhandledRejection", (e) => { - console.error(e) +indexChartsToAlgolia().catch(async (e) => { + console.error("Error in indexChartsToAlgolia:", e) + Sentry.captureException(e) + await Sentry.close() process.exit(1) }) - -void indexChartsToAlgolia() diff --git a/baker/algolia/indexExplorerViewsAndChartsToAlgolia.ts b/baker/algolia/indexExplorerViewsAndChartsToAlgolia.ts index eeb38b3478..e2ea4d1b8b 100644 --- a/baker/algolia/indexExplorerViewsAndChartsToAlgolia.ts +++ b/baker/algolia/indexExplorerViewsAndChartsToAlgolia.ts @@ -2,6 +2,7 @@ // set up before any errors are thrown. import "../../serverUtils/instrument.js" +import * as Sentry from "@sentry/node" import * as db from "../../db/db.js" import { ALGOLIA_INDEXING } from "../../settings/serverSettings.js" import { getAlgoliaClient } from "./configureAlgolia.js" @@ -55,9 +56,9 @@ const indexExplorerViewsAndChartsToAlgolia = async () => { console.log(`Indexing complete`) } -process.on("unhandledRejection", (e) => { - console.error(e) +indexExplorerViewsAndChartsToAlgolia().catch(async (e) => { + console.error("Error in indexExplorerViewsAndChartsToAlgolia:", e) + Sentry.captureException(e) + await Sentry.close() process.exit(1) }) - -void indexExplorerViewsAndChartsToAlgolia() diff --git a/baker/algolia/indexExplorerViewsToAlgolia.ts b/baker/algolia/indexExplorerViewsToAlgolia.ts index 30ccb3af69..34db110ea0 100644 --- a/baker/algolia/indexExplorerViewsToAlgolia.ts +++ b/baker/algolia/indexExplorerViewsToAlgolia.ts @@ -2,6 +2,7 @@ // set up before any errors are thrown. import "../../serverUtils/instrument.js" +import * as Sentry from "@sentry/node" import * as db from "../../db/db.js" import { ALGOLIA_INDEXING } from "../../settings/serverSettings.js" import { getAlgoliaClient } from "./configureAlgolia.js" @@ -30,9 +31,9 @@ const indexExplorerViewsToAlgolia = async () => { console.log(`Indexing complete`) } -process.on("unhandledRejection", (e) => { - console.error(e) +indexExplorerViewsToAlgolia().catch(async (e) => { + console.error("Error in indexExplorerViewsToAlgolia:", e) + Sentry.captureException(e) + await Sentry.close() process.exit(1) }) - -void indexExplorerViewsToAlgolia() diff --git a/baker/algolia/indexPagesToAlgolia.tsx b/baker/algolia/indexPagesToAlgolia.tsx index 2a0bf6a109..155e141e1d 100644 --- a/baker/algolia/indexPagesToAlgolia.tsx +++ b/baker/algolia/indexPagesToAlgolia.tsx @@ -1,3 +1,8 @@ +// This should be imported as early as possible so the global error handler is +// set up before any errors are thrown. +import "../../serverUtils/instrument.js" + +import * as Sentry from "@sentry/node" import * as db from "../../db/db.js" import { ALGOLIA_INDEXING } from "../../settings/serverSettings.js" import { getAlgoliaClient } from "./configureAlgolia.js" @@ -25,9 +30,9 @@ const indexPagesToAlgolia = async () => { process.exit(0) } -process.on("unhandledRejection", (e) => { - console.error(e) +indexPagesToAlgolia().catch(async (e) => { + console.error("Error in indexPagesToAlgolia:", e) + Sentry.captureException(e) + await Sentry.close() process.exit(1) }) - -void indexPagesToAlgolia()