浏览代码

Fix to AsyncRequest - After an update a while ago, Relay exceptions stopped getting the extra call stacks that the AsyncRequest maintains, since something on the service side of things handles exceptions on its own. This switches the logging a bit to ensure call stacks for our code are presented.

/main/staging/asyncrequest_log_fix
nathaniel.buck@unity3d.com 3 年前
当前提交
5418606d
共有 2 个文件被更改,包括 7 次插入5 次删除
  1. 8
      Assets/Scripts/Infrastructure/AsyncRequest.cs
  2. 4
      Assets/Scripts/Tests/PlayMode/LobbyRoundtripTests.cs

8
Assets/Scripts/Infrastructure/AsyncRequest.cs


catch (Exception e)
{
ParseServiceException(e);
Exception eFull = new Exception($"Call stack before async call:\n{currentTrace}\n", e); // TODO: Are we still missing Relay exceptions after the update?
throw eFull;
UnityEngine.Debug.LogError($"AsyncRequest threw an exception. Call stack before async call:\n{currentTrace}\n"); // Note that we log here instead of creating a new Exception in case of a change in calling context during the async call. E.g. Relay has its own exception handling that would intercept this call stack.
throw;
}
finally
{ onComplete?.Invoke();

catch (Exception e)
{
ParseServiceException(e);
Exception eFull = new Exception($"Call stack before async call:\n{currentTrace}\n", e);
throw eFull;
UnityEngine.Debug.LogError($"AsyncRequest threw an exception. Call stack before async call:\n{currentTrace}\n");
throw;
}
finally
{ onComplete?.Invoke(result);

4
Assets/Scripts/Tests/PlayMode/LobbyRoundtripTests.cs


[UnityTest]
public IEnumerator OnCompletesOnFailure()
{
LogAssert.Expect(LogType.Exception, new Regex(".*400 Bad Request.*"));
if (!m_didSigninComplete)
yield return new WaitForSeconds(3);
if (!m_didSigninComplete)

LogAssert.ignoreFailingMessages = true; // Multiple errors will appears for the exception.
LobbyAPIInterface.CreateLobbyAsync("ThisStringIsInvalidHere", "lobby name", 123, false, m_mockUserData, (r) => { didComplete = (r == null); });
float timeout = 5;
while (didComplete == null && timeout > 0)

LogAssert.ignoreFailingMessages = false;
Assert.Greater(timeout, 0, "Timeout check");
Assert.NotNull(didComplete, "Should have called onComplete, even if the async request failed.");
Assert.True(didComplete, "The returned object will be null, so expect to need to handle it.");

正在加载...
取消
保存