Fix prototype manager Index exceptions

Index<T> was documented to throw KeyNotFoundException, but actually threw UnknownPrototypeException. Index(Type type, string id) threw KeyNotFoundException.

This has now been made consistent to be UnknownPrototypeException everywhere.
This commit is contained in:
PJB3005
2025-06-26 16:58:35 +02:00
parent 98313ae369
commit 6436ff8040
3 changed files with 12 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ END TEMPLATE-->
### Breaking changes
*None yet*
* `IPrototypeManager.Index(Type kind, string id)` now throws `UnknownPrototypeException` instead of `KeyNotFoundException`, for consistency with `IPrototypeManager.Index<T>`.
### New features
@@ -43,7 +43,7 @@ END TEMPLATE-->
### Bugfixes
*None yet*
* Fixed documentation for `IPrototypeManager.Index<T>` stating that `KeyNotFoundException` gets thrown, when in actuality `UnknownPrototypeException` gets thrown.
### Other

View File

@@ -91,7 +91,7 @@ public interface IPrototypeManager
/// <summary>
/// Index for a <see cref="IPrototype"/> by ID.
/// </summary>
/// <exception cref="KeyNotFoundException">
/// <exception cref="UnknownPrototypeException">
/// Thrown if the type of prototype is not registered.
/// </exception>
T Index<T>(string id) where T : class, IPrototype;
@@ -105,7 +105,7 @@ public interface IPrototypeManager
/// <summary>
/// Index for a <see cref="IPrototype"/> by ID.
/// </summary>
/// <exception cref="KeyNotFoundException">
/// <exception cref="UnknownPrototypeException">
/// Thrown if the ID does not exist or the kind of prototype is not registered.
/// </exception>
IPrototype Index(Type kind, string id);

View File

@@ -279,7 +279,14 @@ namespace Robust.Shared.Prototypes
throw new InvalidOperationException("No prototypes have been loaded yet.");
}
return _kinds[kind].Instances[id];
try
{
return _kinds[kind].Instances[id];
}
catch (KeyNotFoundException)
{
throw new UnknownPrototypeException(id, kind);
}
}
/// <inheritdoc />