Misc toolshed fixes (#5340)

* Prevent map/emplace command errors from locking up the server

* Fix EmplaceCommand

* Fix sort commands

* Fix JoinCommand

* changelog

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2024-08-28 14:22:47 +12:00
committed by GitHub
parent ec3a74d268
commit 23a23f7c22
6 changed files with 21 additions and 12 deletions

View File

@@ -43,11 +43,12 @@ END TEMPLATE-->
### Bugfixes
*None yet*
* Fixed a bug where the client might not add entities to the broadphase/lookup components.
* Fixed various toolshed commands not working, including `sort`, `sortdown` `join` (for strings), and `emplace`
### Other
*None yet*
* Toolshed command blocks now stop executing if previous errors were not handled / cleared.
### Internal

View File

@@ -16,7 +16,7 @@ public sealed class EmplaceCommand : ToolshedCommand
public override Type[] TypeParameterParsers => new[] {typeof(Type)};
[CommandImplementation, TakesPipedTypeAsGeneric]
TOut Emplace<TIn, TOut>(
TOut Emplace<TOut, TIn>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] TIn value,
[CommandArgument] Block<TOut> block
@@ -27,7 +27,7 @@ public sealed class EmplaceCommand : ToolshedCommand
}
[CommandImplementation, TakesPipedTypeAsGeneric]
IEnumerable<TOut> Emplace<TIn, TOut>(
IEnumerable<TOut> Emplace<TOut, TIn>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] IEnumerable<TIn> value,
[CommandArgument] Block<TOut> block

View File

@@ -5,11 +5,9 @@ using Robust.Shared.Toolshed.Syntax;
namespace Robust.Shared.Toolshed.Commands.Generic.Ordering;
[ToolshedCommand, MapLikeCommand]
[ToolshedCommand]
public sealed class SortCommand : ToolshedCommand
{
public override Type[] TypeParameterParsers => new[] {typeof(Type)};
[CommandImplementation, TakesPipedTypeAsGeneric]
public IEnumerable<T> Sort<T>(
[CommandInvocationContext] IInvocationContext ctx,

View File

@@ -5,11 +5,9 @@ using Robust.Shared.Toolshed.Syntax;
namespace Robust.Shared.Toolshed.Commands.Generic.Ordering;
[ToolshedCommand, MapLikeCommand]
[ToolshedCommand]
public sealed class SortDownCommand : ToolshedCommand
{
public override Type[] TypeParameterParsers => new[] {typeof(Type)};
[CommandImplementation, TakesPipedTypeAsGeneric]
public IEnumerable<T> Sort<T>(
[CommandInvocationContext] IInvocationContext ctx,

View File

@@ -7,7 +7,7 @@ namespace Robust.Shared.Toolshed.Commands.Math;
[ToolshedCommand]
public sealed class JoinCommand : ToolshedCommand
{
[CommandImplementation, TakesPipedTypeAsGeneric]
[CommandImplementation]
public string Join(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] string x,
@@ -18,7 +18,7 @@ public sealed class JoinCommand : ToolshedCommand
if (yVal is null)
return x;
return x + y;
return x + yVal;
}
[CommandImplementation, TakesPipedTypeAsGeneric]

View File

@@ -74,6 +74,18 @@ public sealed class CommandRun
public object? Invoke(object? input, IInvocationContext ctx, bool reportErrors = true)
{
// TODO TOOLSHED
// improve error handling. Most expression invokers don't bother to check for errors.
// This especially applies to all map / emplace / sort commands.
// A simple error while enumerating entities could lock up the server.
if (ctx.GetErrors().Any())
{
// Attempt to prevent O(n^2) growth in errors due to people repeatedly evaluating expressions without
// checking for errors.
throw new Exception($"Improperly handled Toolshed errors");
}
var ret = input;
foreach (var (cmd, span) in Commands)
{