From 42bf34064a0691e7b2b563476287c977d727c768 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 26 Jan 2020 22:12:38 +0100 Subject: [PATCH] Adding a try catch in the crawler --- Kyoo/Controllers/Crawler.cs | 12 +++++++++--- Kyoo/Controllers/Transcoder/TranscoderAPI.cs | 4 ++-- Kyoo/Program.cs | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Kyoo/Controllers/Crawler.cs b/Kyoo/Controllers/Crawler.cs index 38f1ad2a..c42c28e3 100644 --- a/Kyoo/Controllers/Crawler.cs +++ b/Kyoo/Controllers/Crawler.cs @@ -36,7 +36,14 @@ namespace Kyoo.Controllers if (isRunning) return; isRunning = true; - StartAsync(cancellation.Token); + try + { + StartAsync(cancellation.Token); + } + catch (Exception ex) + { + Console.Error.WriteLine($"Unknown exception thrown durring libraries scan.\nException: {ex.Message}"); + } } public void Cancel() @@ -52,7 +59,6 @@ namespace Kyoo.Controllers IEnumerable episodes = libraryManager.GetAllEpisodes(); IEnumerable libraries = libraryManager.GetLibraries(); - Debug.WriteLine("&Crawler started"); foreach (Episode episode in episodes) { if (!File.Exists(episode.Path)) @@ -63,7 +69,7 @@ namespace Kyoo.Controllers await Scan(library, cancellationToken); isRunning = false; - Debug.WriteLine("&Crawler stopped"); + Console.WriteLine("Scan finished!"); } private async Task Scan(Library library, CancellationToken cancellationToken) diff --git a/Kyoo/Controllers/Transcoder/TranscoderAPI.cs b/Kyoo/Controllers/Transcoder/TranscoderAPI.cs index b95c0584..85bcaf16 100644 --- a/Kyoo/Controllers/Transcoder/TranscoderAPI.cs +++ b/Kyoo/Controllers/Transcoder/TranscoderAPI.cs @@ -56,10 +56,10 @@ namespace Kyoo.Controllers.TranscoderLink } } else - tracks = null; + tracks = new Track[0]; free(ptr); - Console.WriteLine("&" + tracks?.Length + " tracks got at: " + path); + Console.WriteLine(tracks.Length + " tracks got at: " + path); } public static void ExtractSubtitles(string path, string outPath, out Track[] tracks) diff --git a/Kyoo/Program.cs b/Kyoo/Program.cs index 925d7334..d905c9cc 100644 --- a/Kyoo/Program.cs +++ b/Kyoo/Program.cs @@ -1,9 +1,9 @@ +using System; using System.Threading.Tasks; using Kyoo.Controllers; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; namespace Kyoo { @@ -13,6 +13,7 @@ namespace Kyoo { IWebHost host = CreateWebHostBuilder(args).Build(); + Console.WriteLine($"Running as: {Environment.UserName}"); using (IServiceScope serviceScope = host.Services.CreateScope()) { IPluginManager pluginManager = serviceScope.ServiceProvider.GetService();