From 881686e99485ff2e39c2f3637d5b7f0bfce9f672 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 12 Aug 2013 19:14:03 -0700 Subject: [PATCH] Throw exception when unable to get size from newznab feed --- NzbDrone.Core/Indexers/Newznab/NewznabParser.cs | 9 ++++++++- .../Indexers/Newznab/SizeParsingException.cs | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 NzbDrone.Core/Indexers/Newznab/SizeParsingException.cs diff --git a/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs b/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs index e04fe077f..519953085 100644 --- a/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs +++ b/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs @@ -2,6 +2,7 @@ using System.Drawing; using System.Linq; using System.Xml.Linq; +using NLog; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Indexers.Newznab @@ -20,7 +21,13 @@ protected override ReportInfo PostProcessor(XElement item, ReportInfo currentRes if (currentResult != null) { var attributes = item.Elements(NewznabNamespace + "attr"); - var sizeElement = attributes.Single(e => e.Attribute("name").Value == "size"); + var sizeElement = attributes.SingleOrDefault(e => e.Attribute("name").Value == "size"); + + if (sizeElement == null) + { + var message = String.Format("Unable to parse size from: {0} [{1}]", currentResult.Title, currentResult.Indexer); + throw new SizeParsingException(message); + } currentResult.Size = Convert.ToInt64(sizeElement.Attribute("value").Value); } diff --git a/NzbDrone.Core/Indexers/Newznab/SizeParsingException.cs b/NzbDrone.Core/Indexers/Newznab/SizeParsingException.cs new file mode 100644 index 000000000..33735a7ba --- /dev/null +++ b/NzbDrone.Core/Indexers/Newznab/SizeParsingException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.Indexers.Newznab +{ + public class SizeParsingException : Exception + { + public SizeParsingException(string message) : base(message) + { + } + } +}