From e940d5c745501b9096157a08a1ece4f9518dd1e7 Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Sat, 24 Jul 2021 19:50:27 -0600 Subject: [PATCH] Add dimension to machine position debug statements --- src/main/scala/li/cil/oc/server/machine/Machine.scala | 7 +++++-- .../server/machine/luac/NativeLuaArchitecture.scala | 11 +++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/machine/Machine.scala b/src/main/scala/li/cil/oc/server/machine/Machine.scala index 3bc3c81bb..2b187c1ff 100644 --- a/src/main/scala/li/cil/oc/server/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/machine/Machine.scala @@ -780,7 +780,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach catch { case t: Throwable => OpenComputers.log.error( - s"""Unexpected error loading a state of computer at (${host.xPosition}, ${host.yPosition}, ${host.zPosition}). """ + + s"""Unexpected error loading a state of computer at ${machinePosition}. """ + s"""State: ${state.headOption.fold("no state")(_.toString)}. Unless you're upgrading/downgrading across a major version, please report this! Thank you.""", t) close() } @@ -862,7 +862,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach catch { case t: Throwable => OpenComputers.log.error( - s"""Unexpected error saving a state of computer at (${host.xPosition}, ${host.yPosition}, ${host.zPosition}). """ + + s"""Unexpected error saving a state of computer at ${machinePosition}. """ + s"""State: ${state.headOption.fold("no state")(_.toString)}. Unless you're upgrading/downgrading across a major version, please report this! Thank you.""", t) } }) @@ -1039,6 +1039,9 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach // Keep track of time spent executing the computer. cpuTotal += System.nanoTime() - cpuStart } + + /** Helper method for printing the machine position in error messages and debug statements. */ + private def machinePosition = s"(${host.xPosition}, ${host.yPosition}, ${host.zPosition}, ${host.world().provider.dimensionId})" } object Machine extends MachineAPI { diff --git a/src/main/scala/li/cil/oc/server/machine/luac/NativeLuaArchitecture.scala b/src/main/scala/li/cil/oc/server/machine/luac/NativeLuaArchitecture.scala index f87d313d1..ec110a64e 100644 --- a/src/main/scala/li/cil/oc/server/machine/luac/NativeLuaArchitecture.scala +++ b/src/main/scala/li/cil/oc/server/machine/luac/NativeLuaArchitecture.scala @@ -376,7 +376,7 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A try lua.gc(LuaState.GcAction.COLLECT, 0) catch { case t: Throwable => - OpenComputers.log.warn(s"Error cleaning up loaded computer @ (${machine.host.xPosition}, ${machine.host.yPosition}, ${machine.host.zPosition}). This either means the server is badly overloaded or a user created an evil __gc method, accidentally or not.") + OpenComputers.log.warn(s"Error cleaning up loaded computer @ ${machinePosition}. This either means the server is badly overloaded or a user created an evil __gc method, accidentally or not.") machine.crash("error in garbage collector, most likely __gc method timed out") } } catch { @@ -414,19 +414,22 @@ abstract class NativeLuaArchitecture(val machine: api.machine.Machine) extends A try lua.gc(LuaState.GcAction.COLLECT, 0) catch { case t: Throwable => - OpenComputers.log.warn(s"Error cleaning up loaded computer @ (${machine.host.xPosition}, ${machine.host.yPosition}, ${machine.host.zPosition}). This either means the server is badly overloaded or a user created an evil __gc method, accidentally or not.") + OpenComputers.log.warn(s"Error cleaning up loaded computer @ ${machinePosition}. This either means the server is badly overloaded or a user created an evil __gc method, accidentally or not.") machine.crash("error in garbage collector, most likely __gc method timed out") } } catch { case e: LuaRuntimeException => - OpenComputers.log.warn(s"Could not persist computer @ (${machine.host.xPosition}, ${machine.host.yPosition}, ${machine.host.zPosition}).\n${e.toString}" + (if (e.getLuaStackTrace.isEmpty) "" else "\tat " + e.getLuaStackTrace.mkString("\n\tat "))) + OpenComputers.log.warn(s"Could not persist computer @ ${machinePosition}.\n${e.toString}" + (if (e.getLuaStackTrace.isEmpty) "" else "\tat " + e.getLuaStackTrace.mkString("\n\tat "))) nbt.removeTag("state") case e: LuaGcMetamethodException => - OpenComputers.log.warn(s"Could not persist computer @ (${machine.host.xPosition}, ${machine.host.yPosition}, ${machine.host.zPosition}).\n${e.toString}") + OpenComputers.log.warn(s"Could not persist computer @ ${machinePosition}.\n${e.toString}") nbt.removeTag("state") } // Limit memory again. recomputeMemory(machine.host.internalComponents) } + + /** Helper method for printing the machine position in error messages and debug statements. */ + private def machinePosition = s"(${machine.host.xPosition}, ${machine.host.yPosition}, ${machine.host.zPosition}, ${machine.host.world().provider.dimensionId})" }