Error handling in migration to new quality

pull/4/head
Mark McDowall 11 years ago
parent fe4f3d5d1e
commit c9a77e99a0

@ -41,15 +41,22 @@ namespace NzbDrone.Common.Serializer
return JsonConvert.DeserializeObject(json, type, SerializerSetting);
}
public static T TryDeserialize<T>(string json) where T : new()
public static bool TryDeserialize<T>(string json, out T result) where T : new()
{
try
{
return Deserialize<T>(json);
result = Deserialize<T>(json);
return true;
}
catch (JsonReaderException ex)
{
return default(T);
result = default(T);
return false;
}
catch (JsonSerializationException ex)
{
result = default(T);
return false;
}
}

@ -13,11 +13,13 @@ namespace NzbDrone.Core.Datastore.Migration
public class update_with_quality_converters : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
if (!Schema.Table("QualityProfiles").Column("Items").Exists())
{
Alter.Table("QualityProfiles").AddColumn("Items").AsString().Nullable();
}
Execute.WithConnection(ConvertQualityProfiles);
Execute.WithConnection(ConvertQualityModels);
}
@ -80,7 +82,12 @@ namespace NzbDrone.Core.Datastore.Migration
var id = qualityModelReader.GetInt32(0);
var qualityJson = qualityModelReader.GetString(1);
var quality = Json.Deserialize<QualityModel>(qualityJson);
QualityModel quality;
if (!Json.TryDeserialize<QualityModel>(qualityJson, out quality))
{
continue;
}
var qualityNewJson = qualityModelConverter.ToDB(quality);

@ -32,9 +32,9 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
request.AddFile("name", ReadFully(nzb), title, "application/x-nzb");
var response = Json.TryDeserialize<SabAddResponse>(ProcessRequest(request, action));
SabAddResponse response;
if (response == null)
if (!Json.TryDeserialize<SabAddResponse>(ProcessRequest(request, action), out response))
{
response = new SabAddResponse();
response.Status = true;
@ -87,9 +87,9 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
throw new ApplicationException("Unable to connect to SABnzbd, please check your settings");
}
var result = Json.TryDeserialize<SabJsonError>(response.Content);
SabJsonError result;
if (result == null)
if (!Json.TryDeserialize<SabJsonError>(response.Content, out result))
{
//Handle plain text responses from SAB
result = new SabJsonError();

Loading…
Cancel
Save