Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//RUNTIME ERROR, RETURN TRUE
var/error_loop_count = 0

/world/Error()
error_loop_count++
if(error_loop_count > 1)
world.log << "this is a test failure"
return
TestProc()

/proc/SubError()
CRASH("we're doing an error!")

/proc/TestProc()
SubError()

/proc/RunTest()
TestProc()
return error_loop_count == 1
10 changes: 7 additions & 3 deletions OpenDreamRuntime/DreamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public ClientObjectReference GetClientReference(DreamObjectAtom atom) {
}
}

public void HandleException(Exception e, string msg = "", string file = "", int line = 0) {
public void HandleException(Exception e, string msg = "", string file = "", int line = 0, bool inWorldError = false) {
if (string.IsNullOrEmpty(msg)) { // Just print the C# exception if we don't override the message
msg = e.Message;
}
Expand All @@ -452,8 +452,12 @@ public void HandleException(Exception e, string msg = "", string file = "", int
obj.Desc = new DreamValue(msg);
obj.Line = new DreamValue(line);
obj.File = new DreamValue(file);

WorldInstance.SpawnProc("Error", usr: null, new DreamValue(obj));
if (!inWorldError) // if an error occurs in /world/Error(), don't call it again
WorldInstance.SpawnProc("Error", usr: null, new DreamValue(obj));
else {
_sawmill.Error("CRITICAL: An error occurred in /world/Error()");
WriteWorldLog(msg);
}
}

public void OptionalException<T>(WarningCode code, string exceptionText) where T : Exception {
Expand Down
9 changes: 8 additions & 1 deletion OpenDreamRuntime/DreamThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,14 @@ private void HandleException(Exception exception) {
line = source.Item2;
}

dreamMan.HandleException(exception, msg, file, line);
bool inWorldError = _current?.Proc?.OwningType == dreamMan.WorldInstance.ObjectDefinition.TreeEntry && _current.Proc.Name == "Error";
if (!inWorldError && _stack.Count > 0) {
//if we're not directly in /world.Error, check the stack
var top = _stack.ElementAt(_stack.Count - 1); //only the top of the stack can be /world/Error
inWorldError = top.Proc?.OwningType == dreamMan.WorldInstance.ObjectDefinition.TreeEntry && top.Proc?.Name == "Error";
}

dreamMan.HandleException(exception, msg, file, line, inWorldError: inWorldError);
IoCManager.Resolve<IDreamDebugManager>().HandleException(this, exception);
}

Expand Down
Loading