From 6c51d4e6cd05238440c9a69bb5e1e3f17e99f96a Mon Sep 17 00:00:00 2001 From: Pingger Date: Sun, 5 Jun 2016 16:00:09 +0200 Subject: [PATCH 1/4] Removed some duplicate Code --- .../Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs index d3f883ed0d..fbe407f558 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs @@ -181,11 +181,6 @@ bool IMyProgrammableBlock.TryRun(string argument) return false; } - if (!IsFunctional || !IsWorking) - { - return false; - } - string response; var result = this.ExecuteCode(argument ?? "", out response); SetDetailedInfo(response); From 9d45598c902e8b3d1461ba58c7409dbb15e34e90 Mon Sep 17 00:00:00 2001 From: Pingger Date: Sun, 5 Jun 2016 16:24:14 +0200 Subject: [PATCH 2/4] Added Script Stack Trace Added the Scripts StackTrace when an Exception is thrown by the Script, removing all internal calls leading to the Scripts Call. --- .../Game/Entities/Blocks/MyProgrammableBlock.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs index fbe407f558..68c0473b78 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs @@ -456,6 +456,16 @@ public ScriptTerminationReason RunSandboxedProgramAction(Action } } else { response += MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.Message; + // Get both StackTraces + string ExceptionStackTrace = ex.StackTrace; + string[] currentStackTrace = Environment.StackTrace.Split(new string[] {Environment.NewLine}, StringSplitOptions.None); + // Remove All Calls before the Script Call + for (int i = 0; i < currentStackTrace.Length; i++) + { + ExceptionStackTrace.Replace(currentStackTrace[i], ""); + } + // Add Script StackTrace to response Line + response += "\n" + ExceptionStackTrace; OnProgramTermination(ScriptTerminationReason.RuntimeException); } return m_terminationReason; From 9259f0104df04d227bf6ddab225907798a55fbf6 Mon Sep 17 00:00:00 2001 From: Pingger Date: Sun, 5 Jun 2016 20:02:28 +0200 Subject: [PATCH 3/4] Fixed Replace --- .../Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs index 68c0473b78..15a396ecd1 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs @@ -462,7 +462,7 @@ public ScriptTerminationReason RunSandboxedProgramAction(Action // Remove All Calls before the Script Call for (int i = 0; i < currentStackTrace.Length; i++) { - ExceptionStackTrace.Replace(currentStackTrace[i], ""); + ExceptionStackTrace = ExceptionStackTrace.Replace(currentStackTrace[i], ""); } // Add Script StackTrace to response Line response += "\n" + ExceptionStackTrace; From 94b6e77a6b1e329b13ad91da8f3640e2a952cd9e Mon Sep 17 00:00:00 2001 From: Pingger Date: Sun, 5 Jun 2016 21:37:55 +0200 Subject: [PATCH 4/4] Changed to StringBuilder Changed string to StringBuilder so less allocations are made when "replacing" (deleting) the internal calls --- .../Game/Entities/Blocks/MyProgrammableBlock.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs b/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs index 15a396ecd1..eb96a037c7 100644 --- a/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs +++ b/Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs @@ -456,16 +456,20 @@ public ScriptTerminationReason RunSandboxedProgramAction(Action } } else { response += MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.Message; + // Get both StackTraces - string ExceptionStackTrace = ex.StackTrace; + StringBuilder ExceptionStackTrace = new StringBuilder(ex.StackTrace); string[] currentStackTrace = Environment.StackTrace.Split(new string[] {Environment.NewLine}, StringSplitOptions.None); - // Remove All Calls before the Script Call + + // Remove All internal calls before the Script Call for (int i = 0; i < currentStackTrace.Length; i++) { - ExceptionStackTrace = ExceptionStackTrace.Replace(currentStackTrace[i], ""); + ExceptionStackTrace.Replace(currentStackTrace[i], ""); } + // Add Script StackTrace to response Line - response += "\n" + ExceptionStackTrace; + response += "\n" + ExceptionStackTrace.ToString(); + OnProgramTermination(ScriptTerminationReason.RuntimeException); } return m_terminationReason;