From 3fecd81333c3f424faaf8fb76d764a6715d6502a Mon Sep 17 00:00:00 2001 From: Leonid Pershin Date: Thu, 30 Jul 2026 02:00:07 +0300 Subject: [PATCH] Enhance ShowMetadataApplier with logging for poster retrieval failures Updated the ShowMetadataApplier class to include logging for scenarios where show posters are not retrieved successfully. Introduced logging statements to capture warnings when poster URLs are empty or when downloads fail, improving traceability and debugging capabilities. Additionally, updated related tests to ensure proper logging behavior during poster processing. --- .../Metadata/ShowMetadataApplier.cs | 25 ++++++++++++++++++- .../Library/AddShowsToCollectionTests.cs | 9 ++++--- .../Media/ImportMoviesTests.cs | 12 ++++++--- .../Media/MovieImportHandlerTests.cs | 4 ++- .../Metadata/ApplyShowMetadataTests.cs | 6 +++-- .../Metadata/EnrichShowsTests.cs | 4 ++- .../Metadata/ShowMetadataApplierTests.cs | 9 ++++--- 7 files changed, 54 insertions(+), 15 deletions(-) diff --git a/backend/src/TeleWave.Application/Metadata/ShowMetadataApplier.cs b/backend/src/TeleWave.Application/Metadata/ShowMetadataApplier.cs index be6ba6d..b960984 100644 --- a/backend/src/TeleWave.Application/Metadata/ShowMetadataApplier.cs +++ b/backend/src/TeleWave.Application/Metadata/ShowMetadataApplier.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Common.Models; using TeleWave.Application.Library.Genres; @@ -16,7 +17,8 @@ public sealed class ShowMetadataApplier( IMetadataProviderResolver resolver, IImageDownloader downloader, IImageStore imageStore, - GenreMatcher genreMatcher + GenreMatcher genreMatcher, + ILogger logger ) { /// @@ -84,12 +86,28 @@ public sealed class ShowMetadataApplier( CancellationToken cancellationToken ) { + // Три исхода — три разные починки, и снаружи они неразличимы: шоу просто остаётся без + // постера. Пишем в лог, какой именно случился. if (string.IsNullOrEmpty(posterUrl)) + { + logger.LogWarning( + "Постер для «{Show}» не проставлен: источник не вернул ссылку на картинку", + show.Name + ); return null; + } var downloaded = await downloader.DownloadAsync(posterUrl, cancellationToken); if (downloaded is null) + { + // Подробности (статус, исключение) пишет сам загрузчик. + logger.LogWarning( + "Постер для «{Show}» не проставлен: {Url} не скачался", + show.Name, + posterUrl + ); return null; + } var image = Image.Create(ImageCategory.ShowPoster, downloaded.Extension, show.Name); dbContext.Images.Add(image); @@ -99,6 +117,11 @@ public sealed class ShowMetadataApplier( downloaded.Content, cancellationToken ); + logger.LogInformation( + "Постер для «{Show}» сохранён как изображение {ImageId}", + show.Name, + image.Id + ); return image.Id; } } diff --git a/backend/tests/TeleWave.Application.Tests/Library/AddShowsToCollectionTests.cs b/backend/tests/TeleWave.Application.Tests/Library/AddShowsToCollectionTests.cs index d1558a5..5b14064 100644 --- a/backend/tests/TeleWave.Application.Tests/Library/AddShowsToCollectionTests.cs +++ b/backend/tests/TeleWave.Application.Tests/Library/AddShowsToCollectionTests.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Library.Collections.AddShowsToCollection; @@ -98,7 +99,8 @@ public class AddShowsToCollectionTests resolver, Substitute.For(), Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ) ).Handle(new EnrichShowsMetadataCommand([Guid.NewGuid()], "tmdb"), CancellationToken.None); @@ -130,7 +132,8 @@ public class AddShowsToCollectionTests resolver, Substitute.For(), Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ) ).Handle(new EnrichShowsMetadataCommand([clip.Id], "tmdb"), CancellationToken.None); diff --git a/backend/tests/TeleWave.Application.Tests/Media/ImportMoviesTests.cs b/backend/tests/TeleWave.Application.Tests/Media/ImportMoviesTests.cs index 46def3e..2ff7a29 100644 --- a/backend/tests/TeleWave.Application.Tests/Media/ImportMoviesTests.cs +++ b/backend/tests/TeleWave.Application.Tests/Media/ImportMoviesTests.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Library.Genres; @@ -62,7 +63,8 @@ public class ImportMoviesTests resolver, Substitute.For(), Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ); var result = await new ImportMoviesCommandHandler( @@ -296,7 +298,8 @@ public class ImportMoviesTests resolver, Substitute.For(), Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ); var result = await new AutoAttachMovieCommandHandler( db, @@ -346,7 +349,8 @@ public class ImportMoviesTests resolver, Substitute.For(), Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ); var result = await new AutoAttachMovieCommandHandler( diff --git a/backend/tests/TeleWave.Application.Tests/Media/MovieImportHandlerTests.cs b/backend/tests/TeleWave.Application.Tests/Media/MovieImportHandlerTests.cs index c67db2f..6d6ee3a 100644 --- a/backend/tests/TeleWave.Application.Tests/Media/MovieImportHandlerTests.cs +++ b/backend/tests/TeleWave.Application.Tests/Media/MovieImportHandlerTests.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Library.Genres; @@ -38,7 +39,8 @@ public class MovieImportHandlerTests resolver, Substitute.For(), Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ); [Fact] diff --git a/backend/tests/TeleWave.Application.Tests/Metadata/ApplyShowMetadataTests.cs b/backend/tests/TeleWave.Application.Tests/Metadata/ApplyShowMetadataTests.cs index 5d9bb36..7b34431 100644 --- a/backend/tests/TeleWave.Application.Tests/Metadata/ApplyShowMetadataTests.cs +++ b/backend/tests/TeleWave.Application.Tests/Metadata/ApplyShowMetadataTests.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Library.Genres; @@ -82,7 +83,8 @@ public class ApplyShowMetadataTests arranged.Resolver, Substitute.For(), Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ) ); diff --git a/backend/tests/TeleWave.Application.Tests/Metadata/EnrichShowsTests.cs b/backend/tests/TeleWave.Application.Tests/Metadata/EnrichShowsTests.cs index 09bd961..8d240d7 100644 --- a/backend/tests/TeleWave.Application.Tests/Metadata/EnrichShowsTests.cs +++ b/backend/tests/TeleWave.Application.Tests/Metadata/EnrichShowsTests.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Library.Genres; @@ -122,7 +123,8 @@ public class EnrichShowsTests resolver, Substitute.For(), Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ); var result = await new EnrichShowsMetadataCommandHandler(db, resolver, applier).Handle( diff --git a/backend/tests/TeleWave.Application.Tests/Metadata/ShowMetadataApplierTests.cs b/backend/tests/TeleWave.Application.Tests/Metadata/ShowMetadataApplierTests.cs index 1eb4740..10c49b1 100644 --- a/backend/tests/TeleWave.Application.Tests/Metadata/ShowMetadataApplierTests.cs +++ b/backend/tests/TeleWave.Application.Tests/Metadata/ShowMetadataApplierTests.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.Text; +using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Library.Genres; @@ -97,7 +98,8 @@ public class ShowMetadataApplierTests resolver, Substitute.For(), Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ); var result = await applier.ApplyAsync( @@ -148,7 +150,8 @@ public class ShowMetadataApplierTests resolver, downloader ?? Substitute.For(), store ?? Substitute.For(), - new GenreMatcher(db) + new GenreMatcher(db), + NullLogger.Instance ); }