Improve UnknownPrototypeException error message (#4566)

This commit is contained in:
Leon Friedrich
2023-11-13 05:22:05 +11:00
committed by GitHub
parent 216292c849
commit b3f0e467ee
2 changed files with 9 additions and 18 deletions

View File

@@ -28,22 +28,13 @@ public class PrototypeLoadException : Exception
[Virtual]
public class UnknownPrototypeException : Exception
{
public override string Message => "Unknown prototype: " + Prototype;
public readonly string? Prototype;
public override string Message => $"Unknown {Kind.Name} prototype: {Prototype}" ;
public readonly string Prototype;
public readonly Type Kind;
public UnknownPrototypeException(string prototype)
public UnknownPrototypeException(string prototype, Type kind)
{
Prototype = prototype;
}
public UnknownPrototypeException(SerializationInfo info, StreamingContext context) : base(info, context)
{
Prototype = (string?) info.GetValue("prototype", typeof(string));
}
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("prototype", Prototype, typeof(string));
Kind = kind;
}
}

View File

@@ -196,7 +196,7 @@ namespace Robust.Shared.Prototypes
}
catch (KeyNotFoundException)
{
throw new UnknownPrototypeException(id);
throw new UnknownPrototypeException(id, typeof(T));
}
}
@@ -594,7 +594,7 @@ namespace Robust.Shared.Prototypes
{
if (!_kinds.TryGetValue(typeof(T), out var index))
{
throw new UnknownPrototypeException(id);
throw new UnknownPrototypeException(id, typeof(T));
}
return index.Instances.ContainsKey(id);
@@ -625,7 +625,7 @@ namespace Robust.Shared.Prototypes
{
if (!_kinds.TryGetValue(kind, out var index))
{
throw new UnknownPrototypeException(id);
throw new UnknownPrototypeException(id, kind);
}
return index.Instances.TryGetValue(id, out prototype);
@@ -648,7 +648,7 @@ namespace Robust.Shared.Prototypes
{
if (!_kinds.TryGetValue(typeof(T), out var index))
{
throw new UnknownPrototypeException(id);
throw new UnknownPrototypeException(id, typeof(T));
}
return index.Results.ContainsKey(id);