From 4d662695ba402e2457969b0d65b17985abec35bf Mon Sep 17 00:00:00 2001 From: ujwalakhaire Date: Fri, 4 May 2018 15:36:05 -0700 Subject: [PATCH] Bugfix/handle empty stack (#4549) * Added a check for count before poping from stack. * Fixed test to reflect actual expected exception. --- CSharp/Library/Microsoft.Bot.Builder/Fibers/Fiber.cs | 6 +++++- CSharp/Tests/Microsoft.Bot.Builder.Tests/FiberTests.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CSharp/Library/Microsoft.Bot.Builder/Fibers/Fiber.cs b/CSharp/Library/Microsoft.Bot.Builder/Fibers/Fiber.cs index d182b7e64e..9b1132cbb5 100644 --- a/CSharp/Library/Microsoft.Bot.Builder/Fibers/Fiber.cs +++ b/CSharp/Library/Microsoft.Bot.Builder/Fibers/Fiber.cs @@ -234,7 +234,11 @@ async Task> IFiberLoop.PollAsync(C context, CancellationToken token) } catch (Exception error) { - this.stack.Pop(); + if (this.stack.Count != 0) + { + this.stack.Pop(); + } + if (this.stack.Count == 0) { throw; diff --git a/CSharp/Tests/Microsoft.Bot.Builder.Tests/FiberTests.cs b/CSharp/Tests/Microsoft.Bot.Builder.Tests/FiberTests.cs index 46df23ed46..cdf30a2330 100644 --- a/CSharp/Tests/Microsoft.Bot.Builder.Tests/FiberTests.cs +++ b/CSharp/Tests/Microsoft.Bot.Builder.Tests/FiberTests.cs @@ -330,7 +330,7 @@ public async Task Fiber_OneCall_NeedDone() } [TestMethod] - [ExpectedException(typeof(InvalidOperationException))] + [ExpectedException(typeof(InvalidNeedException))] public async Task Fiber_OneCall_ThenDone_Throws() { // arrange