Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
Bugfix/sentry and fixes (#243)
Joseph Milazzo5083608f2451
diff --git a/API/Data/DbFactory.cs b/API/Data/DbFactory.csindex e55ed0cd8..804cd75bb 100644--- a/API/Data/DbFactory.cs+++ b/API/Data/DbFactory.cs@@ -1,4 +1,5 @@-using System.Collections.Generic;+using System;+using System.Collections.Generic;using API.Entities;using API.Entities.Enums;using API.Parser;@@ -21,7 +22,8 @@ namespace API.DataNormalizedName = Parser.Parser.Normalize(name),SortName = name,Summary = string.Empty,- Volumes = new List<Volume>()+ Volumes = new List<Volume>(),+ Metadata = SeriesMetadata(Array.Empty<CollectionTag>())};}diff --git a/API/Program.cs b/API/Program.csindex 4ea8f4e40..d9715c0f6 100644--- a/API/Program.cs+++ b/API/Program.cs@@ -100,11 +100,12 @@ namespace APIoptions.AddExceptionFilterForType<NetVips.VipsException>();options.AddExceptionFilterForType<InvalidDataException>();options.AddExceptionFilterForType<KavitaException>();-+options.BeforeSend = sentryEvent =>{if (sentryEvent.Exception != null- && sentryEvent.Exception.Message.Contains("[GetCoverImage] This archive cannot be read:"))+ && sentryEvent.Exception.Message.Contains("[GetCoverImage] This archive cannot be read:")+ && sentryEvent.Exception.Message.Contains("[BookService] ")){return null; // Don't send this event to Sentry}diff --git a/API/Services/BookService.cs b/API/Services/BookService.csindex 20de5f92c..c5a3e26f5 100644--- a/API/Services/BookService.cs+++ b/API/Services/BookService.cs@@ -156,22 +156,31 @@ namespace API.Servicespublic string GetSummaryInfo(string filePath){if (!IsValidFile(filePath)) return string.Empty;-- using var epubBook = EpubReader.OpenBook(filePath);- return epubBook.Schema.Package.Metadata.Description;++ try+ {+ using var epubBook = EpubReader.OpenBook(filePath);+ return epubBook.Schema.Package.Metadata.Description;+ }+ catch (Exception ex)+ {+ _logger.LogError(ex, "[BookService] There was an exception getting summary, defaulting to empty string");+ }++ return string.Empty;}private bool IsValidFile(string filePath){if (!File.Exists(filePath)){- _logger.LogError("Book {EpubFile} could not be found", filePath);+ _logger.LogError("[BookService] Book {EpubFile} could not be found", filePath);return false;}if (Parser.Parser.IsBook(filePath)) return true;- _logger.LogError("Book {EpubFile} is not a valid EPUB", filePath);+ _logger.LogError("[BookService] Book {EpubFile} is not a valid EPUB", filePath);return false;}@@ -186,7 +195,7 @@ namespace API.Services}catch (Exception ex){- _logger.LogError(ex, "There was an exception getting number of pages, defaulting to 0");+ _logger.LogError(ex, "[BookService] There was an exception getting number of pages, defaulting to 0");}return 0;@@ -238,7 +247,7 @@ namespace API.Services}catch (Exception ex){- _logger.LogError(ex, "There was an exception when opening epub book: {FileName}", filePath);+ _logger.LogError(ex, "[BookService] There was an exception when opening epub book: {FileName}", filePath);}return null;@@ -257,7 +266,7 @@ namespace API.Services// Try to get the cover image from OPF file, if not set, try to parse it from all the files, then result to the first one.var coverImageContent = epubBook.Content.Cover?? epubBook.Content.Images.Values.FirstOrDefault(file => Parser.Parser.IsCoverImage(file.FileName))- ?? epubBook.Content.Images.Values.First();+ ?? epubBook.Content.Images.Values.FirstOrDefault();if (coverImageContent == null) return Array.Empty<byte>();@@ -273,7 +282,7 @@ namespace API.Services}catch (Exception ex){- _logger.LogError(ex, "There was a critical error and prevented thumbnail generation on {BookFile}. Defaulting to no cover image", fileFilePath);+ _logger.LogError(ex, "[BookService] There was a critical error and prevented thumbnail generation on {BookFile}. Defaulting to no cover image", fileFilePath);}return Array.Empty<byte>();