Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Programmable block better exception handling #537

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions Sources/Sandbox.Game/Game/Entities/Blocks/MyProgrammableBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -461,6 +456,20 @@ public ScriptTerminationReason RunSandboxedProgramAction(Action<IMyGridProgram>
}
} else {
response += MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Exception_ExceptionCaught) + ex.Message;

// Get both StackTraces
StringBuilder ExceptionStackTrace = new StringBuilder(ex.StackTrace);
string[] currentStackTrace = Environment.StackTrace.Split(new string[] {Environment.NewLine}, StringSplitOptions.None);

// Remove All internal 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.ToString();

OnProgramTermination(ScriptTerminationReason.RuntimeException);
}
return m_terminationReason;
Expand Down