diff --git a/server/managers/BackupManager.js b/server/managers/BackupManager.js index 2697f94ea..102521b71 100644 --- a/server/managers/BackupManager.js +++ b/server/managers/BackupManager.js @@ -48,14 +48,9 @@ class BackupManager { } async init() { - try { - const backupsDirExists = await fs.pathExists(this.backupPath) - if (!backupsDirExists) { - await fs.ensureDir(this.backupPath) - } - } catch (error) { - Logger.error(`[BackupManager] Failed to ensure backup directory at "${this.backupPath}": ${error.message}`) - throw new Error(`[BackupManager] Failed to ensure backup directory at "${this.backupPath}"`, { cause: error }) + const backupsDirExists = await fs.pathExists(this.backupPath) + if (!backupsDirExists) { + await fs.ensureDir(this.backupPath) } await this.loadBackups() diff --git a/server/managers/CacheManager.js b/server/managers/CacheManager.js index 38c0415e9..b44b65de3 100644 --- a/server/managers/CacheManager.js +++ b/server/managers/CacheManager.js @@ -24,15 +24,10 @@ class CacheManager { this.ImageCachePath = Path.join(this.CachePath, 'images') this.ItemCachePath = Path.join(this.CachePath, 'items') - try { - await fs.ensureDir(this.CachePath) - await fs.ensureDir(this.CoverCachePath) - await fs.ensureDir(this.ImageCachePath) - await fs.ensureDir(this.ItemCachePath) - } catch (error) { - Logger.error(`[CacheManager] Failed to create cache directories at "${this.CachePath}": ${error.message}`) - throw new Error(`[CacheManager] Failed to create cache directories at "${this.CachePath}"`, { cause: error }) - } + await fs.ensureDir(this.CachePath) + await fs.ensureDir(this.CoverCachePath) + await fs.ensureDir(this.ImageCachePath) + await fs.ensureDir(this.ItemCachePath) } async handleCoverCache(res, libraryItemId, options = {}) { diff --git a/server/managers/LogManager.js b/server/managers/LogManager.js index 07bb7d401..731dfe70a 100644 --- a/server/managers/LogManager.js +++ b/server/managers/LogManager.js @@ -37,13 +37,8 @@ class LogManager { } async ensureLogDirs() { - try { - await fs.ensureDir(this.DailyLogPath) - await fs.ensureDir(this.ScanLogPath) - } catch (error) { - console.error(`[LogManager] Failed to create log directories at "${this.DailyLogPath}": ${error.message}`) - throw new Error(`[LogManager] Failed to create log directories at "${this.DailyLogPath}"`, { cause: error }) - } + await fs.ensureDir(this.DailyLogPath) + await fs.ensureDir(this.ScanLogPath) } /** @@ -107,20 +102,20 @@ class LogManager { } /** - * - * @param {string} filename + * + * @param {string} filename */ async removeLogFile(filename) { const fullPath = Path.join(this.DailyLogPath, filename) const exists = await fs.pathExists(fullPath) if (!exists) { Logger.error(TAG, 'Invalid log dne ' + fullPath) - this.dailyLogFiles = this.dailyLogFiles.filter((dlf) => dlf !== filename) + this.dailyLogFiles = this.dailyLogFiles.filter(dlf => dlf !== filename) } else { try { await fs.unlink(fullPath) Logger.info(TAG, 'Removed daily log: ' + filename) - this.dailyLogFiles = this.dailyLogFiles.filter((dlf) => dlf !== filename) + this.dailyLogFiles = this.dailyLogFiles.filter(dlf => dlf !== filename) } catch (error) { Logger.error(TAG, 'Failed to unlink log file ' + fullPath) } @@ -128,8 +123,8 @@ class LogManager { } /** - * - * @param {LogObject} logObj + * + * @param {LogObject} logObj */ async logToFile(logObj) { // Fatal crashes get logged to a separate file @@ -157,8 +152,8 @@ class LogManager { } /** - * - * @param {LogObject} logObj + * + * @param {LogObject} logObj */ async logCrashToFile(logObj) { const line = JSON.stringify(logObj) + '\n' @@ -166,18 +161,18 @@ class LogManager { const logsDir = Path.join(global.MetadataPath, 'logs') await fs.ensureDir(logsDir) const crashLogPath = Path.join(logsDir, 'crash_logs.txt') - return fs.writeFile(crashLogPath, line, { flag: 'a+' }).catch((error) => { + return fs.writeFile(crashLogPath, line, { flag: "a+" }).catch((error) => { console.log('[LogManager] Appended crash log', error) }) } /** * Most recent 5000 daily logs - * + * * @returns {string} */ getMostRecentCurrentDailyLogs() { return this.currentDailyLog?.logs.slice(-5000) || '' } } -module.exports = LogManager +module.exports = LogManager \ No newline at end of file diff --git a/server/managers/MigrationManager.js b/server/managers/MigrationManager.js index e302038ff..8635def10 100644 --- a/server/managers/MigrationManager.js +++ b/server/managers/MigrationManager.js @@ -38,12 +38,7 @@ class MigrationManager { if (!(await fs.pathExists(this.configPath))) throw new Error(`Config path does not exist: ${this.configPath}`) this.migrationsDir = path.join(this.configPath, 'migrations') - try { - await fs.ensureDir(this.migrationsDir) - } catch (error) { - Logger.error(`[MigrationManager] Failed to create migrations directory at "${this.migrationsDir}": ${error.message}`) - throw new Error(`[MigrationManager] Failed to create migrations directory at "${this.migrationsDir}"`, { cause: error }) - } + await fs.ensureDir(this.migrationsDir) this.serverVersion = this.extractVersionFromTag(serverVersion) if (!this.serverVersion) throw new Error(`Invalid server version: ${serverVersion}. Expected a version tag like v1.2.3.`) diff --git a/server/managers/PlaybackSessionManager.js b/server/managers/PlaybackSessionManager.js index 1e95727f1..fb12fedaa 100644 --- a/server/managers/PlaybackSessionManager.js +++ b/server/managers/PlaybackSessionManager.js @@ -459,12 +459,7 @@ class PlaybackSessionManager { * Remove all stream folders in `/metadata/streams` */ async removeOrphanStreams() { - try { - await fs.ensureDir(this.StreamsPath) - } catch (error) { - Logger.error(`[PlaybackSessionManager] Failed to create streams directory at "${this.StreamsPath}": ${error.message}`) - throw new Error(`[PlaybackSessionManager] Failed to create streams directory at "${this.StreamsPath}"`, { cause: error }) - } + await fs.ensureDir(this.StreamsPath) try { const streamsInPath = await fs.readdir(this.StreamsPath) for (const streamId of streamsInPath) {