Skip to content

Commit fb143d6

Browse files
committed
Error handling for yielded tasks
1 parent 492eb48 commit fb143d6

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Runtime/Code/Luau/LuauCoreCallbacks.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private struct AwaitingTask
5353
public Task Task;
5454
public MethodInfo Method;
5555
public LuauContext Context;
56+
public Type Type;
5657
}
5758

5859
private struct PropertyGetReflectionCache {
@@ -164,7 +165,7 @@ static void printf(LuauContext context, IntPtr thread, int style, int gameObject
164165
Debug.LogWarning(res, logContext);
165166
} else if (style == 2) {
166167
// The STANDALONE here is just a test:
167-
#if UNITY_STANDALONE
168+
#if UNITY_STANDALONE && !UNITY_EDITOR
168169
Debug.LogWarning("[ERROR] " + res, logContext);
169170
#else
170171
Debug.LogError(res, logContext);
@@ -1499,6 +1500,7 @@ private static int InvokeMethodAsync(LuauContext context, IntPtr thread, Type ty
14991500
Task = task,
15001501
Method = method,
15011502
Context = context,
1503+
Type = type,
15021504
};
15031505

15041506
if (task.IsCompleted) {
@@ -1542,9 +1544,19 @@ private static void ResumeAsyncTask(AwaitingTask awaitingTask, bool immediate =
15421544
}
15431545

15441546
if (awaitingTask.Task.IsFaulted) {
1545-
ThreadDataManager.Error(thread);
1546-
Debug.LogException(awaitingTask.Task.Exception);
1547-
GetLuauDebugTrace(thread);
1547+
var result = -1;
1548+
try {
1549+
LuauError(thread, $"Error: Exception thrown in {awaitingTask.Type.Name} {awaitingTask.Method.Name}: {awaitingTask.Task.Exception.Message}");
1550+
result = LuauPlugin.LuauResumeThread(thread, -1);
1551+
} catch (LuauException e) {
1552+
Debug.LogException(e);
1553+
}
1554+
if (binding != null) {
1555+
binding.m_asyncYield = false;
1556+
binding.m_canResume = result == 1;
1557+
binding.m_error = true;
1558+
}
1559+
15481560
return;
15491561
}
15501562

0 commit comments

Comments
 (0)