Make ContainerFillSystem print contents on failure (#36128)

* Make ContainerFill/EntityTableContainerFill print current contents when failing to spawn an entity

* List each entry on a new line; add fallback for empty
This commit is contained in:
Tayrtahn 2025-03-28 11:37:34 -04:00 committed by deltanedas
parent 4cfb8e36e3
commit c7d98f4daf
1 changed files with 5 additions and 2 deletions

View File

@ -1,3 +1,4 @@
using System.Linq;
using System.Numerics;
using Content.Shared.EntityTable;
using Robust.Shared.Containers;
@ -39,7 +40,8 @@ public sealed class ContainerFillSystem : EntitySystem
var ent = Spawn(proto, coords);
if (!_containerSystem.Insert(ent, container, containerXform: xform))
{
Log.Error($"Entity {ToPrettyString(uid)} with a {nameof(ContainerFillComponent)} failed to insert an entity: {ToPrettyString(ent)}.");
var alreadyContained = container.ContainedEntities.Count > 0 ? string.Join("\n", container.ContainedEntities.Select(e => $"\t - {EntityManager.ToPrettyString(e)}")) : "< empty >";
Log.Error($"Entity {ToPrettyString(uid)} with a {nameof(ContainerFillComponent)} failed to insert an entity: {ToPrettyString(ent)}.\nCurrent contents:\n{alreadyContained}");
_transform.AttachToGridOrMap(ent);
break;
}
@ -72,7 +74,8 @@ public sealed class ContainerFillSystem : EntitySystem
var spawn = Spawn(proto, coords);
if (!_containerSystem.Insert(spawn, container, containerXform: xform))
{
Log.Error($"Entity {ToPrettyString(ent)} with a {nameof(EntityTableContainerFillComponent)} failed to insert an entity: {ToPrettyString(spawn)}.");
var alreadyContained = container.ContainedEntities.Count > 0 ? string.Join("\n", container.ContainedEntities.Select(e => $"\t - {EntityManager.ToPrettyString(e)}")) : "< empty >";
Log.Error($"Entity {ToPrettyString(ent)} with a {nameof(EntityTableContainerFillComponent)} failed to insert an entity: {ToPrettyString(spawn)}.\nCurrent contents:\n{alreadyContained}");
_transform.AttachToGridOrMap(spawn);
break;
}