From 2abeec06fccf6141b55a22e8935ccd791a262a7d Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 29 Oct 2017 21:55:15 -0400 Subject: [PATCH] Fixed: Better import error messages --- .../Disk/DestinationAlreadyExistsException.cs | 29 +++++++++++++++++++ .../Disk/DiskTransferService.cs | 4 +-- .../NotParentException.cs | 4 ++- .../Extensions/PathExtensions.cs | 2 +- src/NzbDrone.Common/NzbDrone.Common.csproj | 3 +- .../MediaFiles/TrackFileMovingService.cs | 3 +- .../TrackImport/ImportApprovedTracks.cs | 10 +++++++ .../RootFolderNotFoundException.cs | 25 ++++++++++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 9 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 src/NzbDrone.Common/Disk/DestinationAlreadyExistsException.cs rename src/NzbDrone.Common/{Exceptions => Disk}/NotParentException.cs (80%) create mode 100644 src/NzbDrone.Core/MediaFiles/TrackImport/RootFolderNotFoundException.cs diff --git a/src/NzbDrone.Common/Disk/DestinationAlreadyExistsException.cs b/src/NzbDrone.Common/Disk/DestinationAlreadyExistsException.cs new file mode 100644 index 000000000..986413742 --- /dev/null +++ b/src/NzbDrone.Common/Disk/DestinationAlreadyExistsException.cs @@ -0,0 +1,29 @@ +using System; +using System.IO; +using System.Runtime.Serialization; + +namespace NzbDrone.Common.Disk +{ + public class DestinationAlreadyExistsException : IOException + { + public DestinationAlreadyExistsException() + { + } + + public DestinationAlreadyExistsException(string message) : base(message) + { + } + + public DestinationAlreadyExistsException(string message, int hresult) : base(message, hresult) + { + } + + public DestinationAlreadyExistsException(string message, Exception innerException) : base(message, innerException) + { + } + + protected DestinationAlreadyExistsException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} diff --git a/src/NzbDrone.Common/Disk/DiskTransferService.cs b/src/NzbDrone.Common/Disk/DiskTransferService.cs index 7bfe67ed1..baf7134a2 100644 --- a/src/NzbDrone.Common/Disk/DiskTransferService.cs +++ b/src/NzbDrone.Common/Disk/DiskTransferService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using System.Threading; @@ -340,7 +340,7 @@ namespace NzbDrone.Common.Disk } else { - throw new IOException(string.Format("Destination already exists. [{0}] to [{1}]", sourcePath, targetPath)); + throw new DestinationAlreadyExistsException($"Destination {targetPath} already exists."); } } } diff --git a/src/NzbDrone.Common/Exceptions/NotParentException.cs b/src/NzbDrone.Common/Disk/NotParentException.cs similarity index 80% rename from src/NzbDrone.Common/Exceptions/NotParentException.cs rename to src/NzbDrone.Common/Disk/NotParentException.cs index d9b78247e..66dae7789 100644 --- a/src/NzbDrone.Common/Exceptions/NotParentException.cs +++ b/src/NzbDrone.Common/Disk/NotParentException.cs @@ -1,4 +1,6 @@ -namespace NzbDrone.Common.Exceptions +using NzbDrone.Common.Exceptions; + +namespace NzbDrone.Common.Disk { public class NotParentException : NzbDroneException { diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index 70c04b773..598bf2494 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -59,7 +59,7 @@ namespace NzbDrone.Common.Extensions { if (!parentPath.IsParentPath(childPath)) { - throw new Exceptions.NotParentException("{0} is not a child of {1}", childPath, parentPath); + throw new NotParentException("{0} is not a child of {1}", childPath, parentPath); } return childPath.Substring(parentPath.Length).Trim(Path.DirectorySeparatorChar); diff --git a/src/NzbDrone.Common/NzbDrone.Common.csproj b/src/NzbDrone.Common/NzbDrone.Common.csproj index 164106cc1..9f424c291 100644 --- a/src/NzbDrone.Common/NzbDrone.Common.csproj +++ b/src/NzbDrone.Common/NzbDrone.Common.csproj @@ -85,6 +85,7 @@ + @@ -129,7 +130,7 @@ - + diff --git a/src/NzbDrone.Core/MediaFiles/TrackFileMovingService.cs b/src/NzbDrone.Core/MediaFiles/TrackFileMovingService.cs index bf25c5d88..70f9a2b6b 100644 --- a/src/NzbDrone.Core/MediaFiles/TrackFileMovingService.cs +++ b/src/NzbDrone.Core/MediaFiles/TrackFileMovingService.cs @@ -1,4 +1,5 @@ using NLog; +using NzbDrone.Common; using NzbDrone.Common.Disk; using NzbDrone.Common.EnsureThat; using NzbDrone.Common.Extensions; @@ -165,7 +166,7 @@ namespace NzbDrone.Core.MediaFiles if (!_diskProvider.FolderExists(rootFolder)) { - throw new DirectoryNotFoundException(string.Format("Root folder '{0}' was not found.", rootFolder)); + throw new TrackImport.RootFolderNotFoundException(string.Format("Root folder '{0}' was not found.", rootFolder)); } var changed = false; diff --git a/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs index 8757bd16a..301ffe40b 100644 --- a/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs +++ b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs @@ -127,6 +127,16 @@ namespace NzbDrone.Core.MediaFiles.TrackImport _eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, oldFiles, newDownload, downloadClientItem)); } + catch (RootFolderNotFoundException e) + { + _logger.Warn(e, "Couldn't import track " + localTrack); + importResults.Add(new ImportResult(importDecision, "Failed to import track, Root folder missing.")); + } + catch (DestinationAlreadyExistsException e) + { + _logger.Warn(e, "Couldn't import track " + localTrack); + importResults.Add(new ImportResult(importDecision, "Failed to import track, Destination already exists.")); + } catch (Exception e) { _logger.Warn(e, "Couldn't import track " + localTrack); diff --git a/src/NzbDrone.Core/MediaFiles/TrackImport/RootFolderNotFoundException.cs b/src/NzbDrone.Core/MediaFiles/TrackImport/RootFolderNotFoundException.cs new file mode 100644 index 000000000..15c3f997c --- /dev/null +++ b/src/NzbDrone.Core/MediaFiles/TrackImport/RootFolderNotFoundException.cs @@ -0,0 +1,25 @@ +using System; +using System.IO; +using System.Runtime.Serialization; + +namespace NzbDrone.Core.MediaFiles.TrackImport +{ + public class RootFolderNotFoundException : DirectoryNotFoundException + { + public RootFolderNotFoundException() + { + } + + public RootFolderNotFoundException(string message) : base(message) + { + } + + public RootFolderNotFoundException(string message, Exception innerException) : base(message, innerException) + { + } + + protected RootFolderNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 8736224bf..01e53521a 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -652,6 +652,7 @@ +