From 2df0d09326d9e1420820a14458d9a2fd2578061a Mon Sep 17 00:00:00 2001 From: Steven Hildreth Date: Mon, 17 Jan 2022 15:06:11 -0600 Subject: [PATCH] Better null handling --- Roadie.Api.Library/Engines/ArtistLookupEngine.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs index 0c35871..38e79f9 100644 --- a/Roadie.Api.Library/Engines/ArtistLookupEngine.cs +++ b/Roadie.Api.Library/Engines/ArtistLookupEngine.cs @@ -184,6 +184,10 @@ namespace Roadie.Library.Engines try { var searchName = name.NormalizeName().ToLower(); + if (string.IsNullOrEmpty(searchName)) + { + return null; + } var searchSortName = !string.IsNullOrEmpty(sortName) ? sortName.NormalizeName().ToLower() : searchName; var specialSearchName = name.ToAlphanumericName(); @@ -257,7 +261,7 @@ namespace Roadie.Library.Engines artistName = artistFromJson?.Name; } - var artist = (await DatabaseQueryForArtistName(artistName).ConfigureAwait(false)).FirstOrDefault(); + var artist = (await DatabaseQueryForArtistName(artistName).ConfigureAwait(false))?.FirstOrDefault(); sw.Stop(); if (artist?.IsValid != true) { @@ -268,6 +272,15 @@ namespace Roadie.Library.Engines if (!string.IsNullOrEmpty(releaseRoadieDataFilename) && File.Exists(releaseRoadieDataFilename)) { artist = CacheManager.CacheSerializer.Deserialize(File.ReadAllText(releaseRoadieDataFilename)); + if (!artist.IsValid) + { + sw.Stop(); + Logger.LogWarning("Artist data is invalid. Data File [{0}]", releaseRoadieDataFilename); + return new OperationResult + { + OperationTime = sw.ElapsedMilliseconds + }; + } var addResult = await Add(artist).ConfigureAwait(false); if (!addResult.IsSuccess) {