From 95ba09220b295c4cf2fc0c3038f631560bb2b92a Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 25 Oct 2023 12:50:57 +0100 Subject: [PATCH] fix: Catch playlist load error --- src/back/index.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/back/index.ts b/src/back/index.ts index 669f7c725..593991010 100644 --- a/src/back/index.ts +++ b/src/back/index.ts @@ -538,17 +538,19 @@ async function prepForInit(message: any): Promise { const playlistDir = path.join(state.config.flashpointPath, state.preferences.playlistFolderPath); const playlistFiles = await fs.promises.readdir(playlistDir, { withFileTypes: true }); for (const file of playlistFiles.filter(f => f.isFile() && f.name.endsWith('.json'))) { - const playlist = await PlaylistFile.readFile(path.join(playlistDir, file.name), (err) => { - console.error('Launcher', `Failed to load Playlist ${file.name}, ERROR:\n${err}`); - }); - // Check for ID collision - const collisionIdx = state.playlists.findIndex(p => p.id === playlist.id); - if (collisionIdx > -1) { - const oldId = playlist.id; - playlist.id = uuid(); - log.warn('Launcher', `Playlist ID Collision - Renamed ID for ${playlist.title} (${oldId}) to ${playlist.id}`); + try { + const playlist = await PlaylistFile.readFile(path.join(playlistDir, file.name)); + // Check for ID collision + const collisionIdx = state.playlists.findIndex(p => p.id === playlist.id); + if (collisionIdx > -1) { + const oldId = playlist.id; + playlist.id = uuid(); + log.warn('Launcher', `Playlist ID Collision - Renamed ID for ${playlist.title} (${oldId}) to ${playlist.id}`); + } + state.playlists.push(playlist); + } catch (err) { + log.error('Launcher', `Failed to load Playlist ${file.name}, ERROR:\n${err}`); } - state.playlists.push(playlist); } console.log('Back - Parsed Playlists');