mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Improve UnknownPrototypeException error message (#4566)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user