egametang/ET · error · NotSupportedException

ETask does not allow call GetResult directly when task not c

Error message

ETask does not allow call GetResult directly when task not completed. Please use 'await'.

What it means

Thrown by ETTask<T>.GetResult when state is neither Succeeded nor Faulted (i.e. still Pending). GetResult is the awaiter's result accessor; the ET contract forbids calling it before the task has completed. Use `await` (which the compiler turns into a state machine that only calls GetResult after IsCompleted), never call GetResult directly.

Source

Thrown at Packages/cn.etetet.core/Scripts/Core/Share/ETTask/ETTask.cs:351

        }

        [DebuggerHidden]
        public T GetResult()
        {
            switch (this.state)
            {
                case AwaiterStatus.Succeeded:
                    T v = this.value;
                    this.Recycle();
                    return v;
                case AwaiterStatus.Faulted:
                    ExceptionDispatchInfo c = this.callback as ExceptionDispatchInfo;
                    this.callback = null;
                    this.Recycle();
                    c?.Throw();
                    return default;
                default:
                    throw new NotSupportedException("ETask does not allow call GetResult directly when task not completed. Please use 'await'.");
            }
        }
        
        public bool IsCompleted
        {
            [DebuggerHidden]
            get
            {
                return state != AwaiterStatus.Pending;
            }
        } 

        [DebuggerHidden]
        public void UnsafeOnCompleted(Action action)
        {
            if (this.state != AwaiterStatus.Pending)
            {
                action?.Invoke();

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Replace direct GetResult() with `await task` so the compiler only calls GetResult after completion.
  2. If you must block, ensure the task is completed first (check IsCompleted), or restructure to push the work into an async method.
  3. Verify the producer code path that should SetResult/SetException this task is actually reached.

Example fix

// before
T value = task.GetAwaiter().GetResult();

// after
T value = await task;
Defensive patterns

Strategy: validation

Validate before calling

// never call GetResult before completion
if (task.IsCompleted)
{
    var v = task.GetAwaiter().GetResult();
}

Try / catch

try
{
    T v = await task;   // preferred: compiler gates GetResult
}
catch (NotSupportedException)
{
    Log.Error("task not completed before GetResult");
}

Prevention

When it happens

Trigger: Calling `task.GetAwaiter().GetResult()` (or task.GetResult()) synchronously on an unfinished ETTask; awaiting a task whose completion was never triggered; .Result/.Wait()-style blocking access on ET tasks.

Common situations: Porting code that used Task<T>.Result / .GetAwaiter().GetResult() blocking reads to ET tasks; forgetting to start the producer that completes the task; calling GetResult from a non-async context instead of awaiting.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/2827790c02f1adc8. Report an issue: GitHub.