show friendly error when parsing a manifest version fails (#308)
This commit is contained in:
parent
b46776a4fb
commit
fb8fefea00
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
|
||||
namespace StardewModdingAPI.Framework.Exceptions
|
||||
{
|
||||
/// <summary>A format exception which provides a user-facing error message.</summary>
|
||||
internal class SParseException : FormatException
|
||||
{
|
||||
/*********
|
||||
** Public methods
|
||||
*********/
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="message">The error message.</param>
|
||||
/// <param name="ex">The underlying exception, if any.</param>
|
||||
public SParseException(string message, Exception ex = null)
|
||||
: base(message, ex) { }
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using StardewModdingAPI.Framework.Exceptions;
|
||||
using StardewModdingAPI.Framework.Models;
|
||||
using StardewModdingAPI.Framework.Serialisation;
|
||||
|
||||
|
@ -45,6 +46,10 @@ namespace StardewModdingAPI.Framework.ModLoading
|
|||
else if (string.IsNullOrWhiteSpace(manifest.EntryDll))
|
||||
error = "its manifest doesn't set an entry DLL.";
|
||||
}
|
||||
catch (SParseException ex)
|
||||
{
|
||||
error = $"parsing its manifest failed: {ex.Message}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = $"parsing its manifest failed:\n{ex.GetLogSummary()}";
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using StardewModdingAPI.Framework.Exceptions;
|
||||
using StardewModdingAPI.Framework.Models;
|
||||
|
||||
namespace StardewModdingAPI.Framework.Serialisation
|
||||
|
@ -50,10 +51,17 @@ namespace StardewModdingAPI.Framework.Serialisation
|
|||
}
|
||||
|
||||
case JTokenType.String:
|
||||
return new SemanticVersion(token.Value<string>());
|
||||
{
|
||||
string str = token.Value<string>();
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
return null;
|
||||
if (!SemanticVersion.TryParse(str, out ISemanticVersion version))
|
||||
throw new SParseException($"Can't parse semantic version from invalid value '{str}', should be formatted like 1.2, 1.2.30, or 1.2.30-beta.");
|
||||
return version;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new FormatException($"Can't parse {token.Type} token as a semantic version, must be an object or string.");
|
||||
throw new SParseException($"Can't parse semantic version from {token.Type}, must be an object or string.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@
|
|||
<Compile Include="Framework\Reflection\PrivateProperty.cs" />
|
||||
<Compile Include="Framework\RequestExitDelegate.cs" />
|
||||
<Compile Include="Framework\SContentManager.cs" />
|
||||
<Compile Include="Framework\Exceptions\SParseException.cs" />
|
||||
<Compile Include="Framework\Serialisation\JsonHelper.cs" />
|
||||
<Compile Include="Framework\Serialisation\SelectiveStringEnumConverter.cs" />
|
||||
<Compile Include="Framework\Serialisation\ManifestFieldConverter.cs" />
|
||||
|
|
Loading…
Reference in New Issue