diff --git a/app/index.ts b/app/index.ts index 40e10fe04..46664f5dd 100644 --- a/app/index.ts +++ b/app/index.ts @@ -3,22 +3,10 @@ * Written by: Alexis Tyler */ -import os from 'os'; import am from 'am'; -import * as Sentry from '@sentry/node'; import { core, loadServer } from '@unraid/core'; import { server } from './server'; -// Send errors to server if enabled -Sentry.init({ - dsn: process.env.SENTRY_DSN, - tracesSampleRate: 1.0, - release: require('../package.json').short(), - environment: process.env.NODE_ENV, - serverName: os.hostname(), - enabled: Boolean(process.env.SENTRY_DSN) -}); - // Boot app am(async () => { // Load core @@ -29,9 +17,6 @@ am(async () => { }, (error: NodeJS.ErrnoException) => { // We should only end here if core has an issue loading - // Send last exception to Sentry - Sentry.captureException(error); - // Log last error console.error(error.message); diff --git a/index.js b/index.js index 531f639b9..84f2e417f 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,20 @@ // @ts-check +const os = require('os'); const path = require('path'); +const Sentry = require('@sentry/node'); const package = require('./package.json'); const { main } = package; +// Send errors to server if enabled +Sentry.init({ + dsn: process.env.SENTRY_DSN, + tracesSampleRate: 1.0, + release: require('./package.json').version, + environment: process.env.NODE_ENV, + serverName: os.hostname(), + enabled: Boolean(process.env.SENTRY_DSN) +}); + if (!main) { throw new Error('Missing main field in package.json'); } @@ -18,6 +30,11 @@ if (process.env.NODE_ENV === 'development') { } } - -const mainPath = path.resolve(__dirname, main); -require(mainPath); \ No newline at end of file +try { + const mainPath = path.resolve(__dirname, main); + require(mainPath); +} catch (error) { + Sentry.captureException(error); + console.error(error.message); + process.exit(1); +} \ No newline at end of file