GithubHelp home page GithubHelp logo

Comments (3)

timcassell avatar timcassell commented on May 10, 2024

With this code:

private void Awake()
{
    Promise.Config.DebugCausalityTracer = Promise.TraceLevel.All;

    LevelOne().Forget();
}

private async Promise LevelOne()
{
    await LevelTwo();
}

private async Promise LevelTwo()
{
    await Promise.Resolved();

    throw new System.Exception();
}

Current master stacktrace:

Exception: Exception of type 'System.Exception' was thrown.
ProtoPromiseExample+<LevelTwo>d__8.MoveNext () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:30)
Rethrow as RejectionException: Exception of type 'Proto.Promises.Internal+RejectionException' was thrown.
ProtoPromiseExample+<LevelOne>d__7.MoveNext () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:25)
Rethrow as UnhandledExceptionInternal: An exception was not handled. -- This exception's Stacktrace contains the causality trace of all async callbacks that ran.
ProtoPromiseExample.LevelOne () (at <97cf00e20a414fd39017285ad6d97db9>:0)
ProtoPromiseExample.Awake () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:20)
UnityEngine.Debug:LogException(Exception)
Proto.Promises.Unity.<UpdateRoutine>d__10:MoveNext() (at Assets/Plugins/ProtoPromise/Core/Promises/Unity/PromiseBehaviour.cs:165)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
Type Method N Mean Code Size Allocated Survived
AwaitPending ProtoPromise_V2 100 385.01 us 13,226 B - 416 B
AwaitResolved ProtoPromise_V2 100 10.43 us 1,906 B 72 B -

With ExceptionDispatchInfo prototype 1:

Exception: Exception of type 'System.Exception' was thrown.
ProtoPromiseExample+<LevelTwo>d__8.MoveNext () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:32)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <c8d0d7b9135640958bff528a1e374758>:0)
Proto.Promises.Async.CompilerServices.PromiseAwaiterVoid.GetResult () (at Assets/Plugins/ProtoPromise/Core/Promises/Internal/AwaitInternal.cs:310)
ProtoPromiseExample+<LevelOne>d__7.MoveNext () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:25)
Rethrow as UnhandledExceptionInternal: An exception was not handled. -- This exception's Stacktrace contains the causality trace of all async callbacks that ran.
ProtoPromiseExample.LevelOne () (at <51200dc91719437a9d3fa38b34e8ed6e>:0)
ProtoPromiseExample.Awake () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:20)
UnityEngine.Debug:LogException(Exception)
Proto.Promises.Unity.<UpdateRoutine>d__10:MoveNext() (at Assets/Plugins/ProtoPromise/Core/Promises/Unity/PromiseBehaviour.cs:165)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
Type Method N Mean Code Size Allocated Survived
AwaitPending ProtoPromise_V2 100 382.70 us 14,356 B - 416 B
AwaitResolved ProtoPromise_V2 100 13.67 us 2,176 B 72 B -

With ExceptionDispatchInfo prototype 2:

Exception: Exception of type 'System.Exception' was thrown.
ProtoPromiseExample+<LevelTwo>d__8.MoveNext () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:32)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <c8d0d7b9135640958bff528a1e374758>:0)
Proto.Promises.Internal+PromiseRef.GetResult[T] (System.Int16 promiseId) (at Assets/Plugins/ProtoPromise/Core/Promises/Internal/AwaitInternal.cs:115)
Proto.Promises.Internal+PromiseAwaiterInternal`1[T].GetResult () (at Assets/Plugins/ProtoPromise/Core/Promises/Internal/AwaitInternal.cs:222)
Proto.Promises.Async.CompilerServices.PromiseAwaiterVoid.GetResult () (at Assets/Plugins/ProtoPromise/Core/Promises/Internal/AwaitInternal.cs:312)
ProtoPromiseExample+<LevelOne>d__7.MoveNext () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:25)
Rethrow as UnhandledExceptionInternal: An exception was not handled. -- This exception's Stacktrace contains the causality trace of all async callbacks that ran.
ProtoPromiseExample.LevelOne () (at <6168812879244f9bbef2b5b8e297fcc9>:0)
ProtoPromiseExample.Awake () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:20)
UnityEngine.Debug:LogException(Exception)
Proto.Promises.Unity.<UpdateRoutine>d__10:MoveNext() (at Assets/Plugins/ProtoPromise/Core/Promises/Unity/PromiseBehaviour.cs:165)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
Type Method N Mean Code Size Allocated Survived
AwaitPending ProtoPromise_V2 100 380.88 us 13,445 B - 416 B
AwaitResolved ProtoPromise_V2 100 10.21 us 1,906 B 72 B -

from protopromise.

timcassell avatar timcassell commented on May 10, 2024

It's rather unfortunate that this method includes the internal stacktraces that we're trying to remove. It would be nice to pair this with #43 to hide all internal methods and not affect performance, but Unity does not yet support .Net 6.

from protopromise.

timcassell avatar timcassell commented on May 10, 2024

Considering that UniTask's stacktrace with the same code looks like this:

Exception: Exception of type 'System.Exception' was thrown.
ProtoPromiseExample+<UniTaskLevelTwo>d__10.MoveNext () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:46)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <c8d0d7b9135640958bff528a1e374758>:0)
Cysharp.Threading.Tasks.UniTask+ExceptionResultSource.GetResult (System.Int16 token) (at Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs:205)
Cysharp.Threading.Tasks.UniTask+Awaiter.GetResult () (at Assets/Plugins/UniTask/Runtime/UniTask.cs:312)
ProtoPromiseExample+<UniTaskLevelOne>d__9.MoveNext () (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:39)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <c8d0d7b9135640958bff528a1e374758>:0)
Cysharp.Threading.Tasks.UniTask+ExceptionResultSource.GetResult (System.Int16 token) (at Assets/Plugins/UniTask/Runtime/UniTask.Factory.cs:205)
Cysharp.Threading.Tasks.UniTask+Awaiter.GetResult () (at Assets/Plugins/UniTask/Runtime/UniTask.cs:312)
Cysharp.Threading.Tasks.UniTaskExtensions.Forget (Cysharp.Threading.Tasks.UniTask task) (at Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs:557)
UnityEngine.Debug:LogException(Exception)
Cysharp.Threading.Tasks.UniTaskScheduler:PublishUnobservedTaskException(Exception) (at Assets/Plugins/UniTask/Runtime/UniTaskScheduler.cs:90)
Cysharp.Threading.Tasks.UniTaskExtensions:Forget(UniTask) (at Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs:561)
ProtoPromiseExample:Awake() (at Assets/Plugins/ProtoPromise/Demo/ProtoPromiseExample.cs:22)

I think the option where we only have 1 extra GetResult() per async frame (prototype 1) is worth it to be able to try/catch on the original exception. I can refactor the PromiseAwaiters to optimize them so that it won't slow down the execution in non-exceptional cases (performance of prototype 2, but without the 2 extra GetResult() frames).

Then it will be primed for .Net 6 to clean up the stack traces for good (which Unity is currently working on).

from protopromise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.