Handle library scan failure gracefully

This commit is contained in:
mikiher 2024-09-12 18:56:52 +03:00
parent 5b09bd8242
commit 1099dbe642

View File

@ -79,6 +79,7 @@ class LibraryScanner {
Logger.info(`[LibraryScanner] Starting${forceRescan ? ' (forced)' : ''} library scan ${libraryScan.id} for ${libraryScan.libraryName}`)
try {
const canceled = await this.scanLibrary(libraryScan, forceRescan)
if (canceled) {
@ -89,7 +90,6 @@ class LibraryScanner {
libraryScan.setComplete()
Logger.info(`[LibraryScanner] Library scan ${libraryScan.id} completed in ${libraryScan.elapsedTimestamp} | ${libraryScan.resultStats}`)
this.librariesScanning = this.librariesScanning.filter((ls) => ls.id !== library.id)
if (canceled && !libraryScan.totalResults) {
task.setFinished('Scan canceled')
@ -111,6 +111,17 @@ class LibraryScanner {
await library.save()
task.setFinished(libraryScan.scanResultsString)
} catch (err) {
libraryScan.setComplete(err)
Logger.error(`[LibraryScanner] Library scan ${libraryScan.id} failed after ${libraryScan.elapsedTimestamp}.`, err)
if (this.cancelLibraryScan[libraryScan.libraryId]) delete this.cancelLibraryScan[libraryScan.libraryId]
task.setFailed(`Scan failed: ${err.message}`)
}
this.librariesScanning = this.librariesScanning.filter((ls) => ls.id !== library.id)
TaskManager.taskFinished(task)
if (libraryScan.totalResults) {