question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unhandled Exception in WithScope

See original GitHub issue

While I might have incorrectly used WithScope this lead to my entire web app crashing on Azure every time it tried to call Twilio. They are having a rough day: https://status.twilio.com/

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? Sentry.AspNetCore @ 3.0.5

Steps to Reproduce

var response = await _httpClient.PostAsync("Messages.json", new FormUrlEncodedContent(content));
if (response.IsSuccessStatusCode == false) {
    SentrySdk.WithScope(async scope => {
        scope.SetExtra("error", await response.Content.ReadAsStringAsync());

        response.EnsureSuccessStatusCode();
    });
}

Expected Result

It would log an exception in Sentry with the response captured.

Actual Result

It crashed my entire web app instance.

Unhandled exception. System.Net.Http.HttpRequestException: Response status code does not indicate success: 500 (INTERNAL SERVER ERROR).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at LoadOne.Infrastructure.Services.SMS.<>c__DisplayClass2_0.<<SendMessage>b__0>d.MoveNext() in C:\projects\webapp\src\LoadOne.Infrastructure\Services\ISMS.cs:line 51
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
   at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bruno-garciacommented, Mar 2, 2021

Oh I would have thought that goes into the UnobservedTaskException but there’s a good explanation here why this is.

1reaction
PaitoAndersoncommented, Mar 2, 2021

This was using .NET Core 3.1. Here is an example:

using System;

namespace AsyncVoid
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ThrowsAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Caught in try/catch  : {ex.Message}");
            }

            Console.ReadKey();
        }

        private static async void ThrowsAsync()
        {
            Console.WriteLine("Throwing...");
            throw new Exception("Boom!");
        }
    }
}
Throwing...
Unhandled exception. System.Exception: Boom!
   at AsyncVoid.Program.ThrowsAsync() in /Users/paitoanderson/Development/AsyncVoid/Program.cs:line 25
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__140_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Node Lambda unhandled exception thrown in Sentry. ...
When running the lambda I get a failure from AWS but the unhandled exception is not captured in Sentry. If I move the...
Read more >
Troubleshooting for Next.js - Browser JavaScript
When you include and configure Sentry, our JavaScript SDK automatically attaches global handlers to capture uncaught exceptions and unhandled promise rejections ...
Read more >
java - Get rid of "Caught an unhandled exception:" in ...
The message is a warning because you are not handling the exception so add an exception handler for the exception to get rid...
Read more >
sentry_flutter | Flutter Package
Sentry SDK for Flutter. This package aims to support different Flutter targets by relying on the many platforms supported by Sentry with native...
Read more >
How to use the @sentry/node.withScope function in @ ...
To help you get started, we've selected a few @sentry/node.withScope examples, based on popular ways it is used in public projects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found