Skip to content

Commit

Permalink
Removed RunAsyncVoid method (#3466)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrosswell authored Jul 10, 2024
1 parent e8855c6 commit 76e9f66
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 57 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Client reports now include dropped spans ([#3463](https://github.com/getsentry/sentry-dotnet/pull/3463))

### API Changes

- Removed SentrySdk.RunAsyncVoid ([#3466](https://github.com/getsentry/sentry-dotnet/pull/3466))

## 4.8.1

### Fixes
Expand Down
7 changes: 0 additions & 7 deletions samples/Sentry.Samples.Maui/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@
Clicked="OnNativeCrashClicked"
HorizontalOptions="Center" />

<Button
x:Name="AsyncVoidCrashBtn"
Text="Capture an exception from an async void method"
SemanticProperties.Hint="Throws an exception in an async void event handler."
Clicked="OnAsyncVoidCrashClicked"
HorizontalOptions="Center" />

</VerticalStackLayout>
</ScrollView>

Expand Down
15 changes: 0 additions & 15 deletions samples/Sentry.Samples.Maui/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ private void OnNativeCrashClicked(object sender, EventArgs e)
#endif
}

private void OnAsyncVoidCrashClicked(object sender, EventArgs e)
{
var client = new HttpClient(new FlakyMessageHandler());

// You can use RunAsyncVoid to call async methods safely from within MAUI event handlers.
SentrySdk.RunAsyncVoid(
async () => await client.GetAsync("https://amostunreliablewebsite.net/"),
ex => _logger.LogWarning(ex, "Error fetching data")
);

// This is an example of the same, omitting any exception handler callback. In this case, the default exception
// handler will be used, which simply captures any exceptions and sends these to Sentry
SentrySdk.RunAsyncVoid(async () => await client.GetAsync("https://amostunreliablewebsite.net/"));
}

private class FlakyMessageHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(
Expand Down
31 changes: 0 additions & 31 deletions src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,37 +691,6 @@ public static void PauseSession()
public static void ResumeSession()
=> CurrentHub.ResumeSession();

/// <summary>
/// Runs an `async void` method safely.
/// </summary>
/// <param name="task">Typically either a method group or an async lambda that executes some async void code</param>
/// <param name="handler">
/// An optional callback that will be run if an exception is thrown. If no callback is provided then by default the
/// exception will be captured and sent to Sentry.
/// </param>
/// <example>
/// <code>
/// SentrySdk.RunAsyncVoid(async () => await MyAsyncMethod(), ex => Console.WriteLine(ex.Message));
/// </code>
/// </example>
public static void RunAsyncVoid(Action task, Action<Exception>? handler = null)
{
var syncCtx = SynchronizationContext.Current;
try
{
handler ??= DefaultExceptionHandler;
SynchronizationContext.SetSynchronizationContext(new ExceptionHandlingSynchronizationContext(handler, syncCtx));
task();
}
finally
{
SynchronizationContext.SetSynchronizationContext(syncCtx);
}
return;

void DefaultExceptionHandler(Exception ex) => CaptureException(ex);
}

/// <summary>
/// Deliberately crashes an application, which is useful for testing and demonstration purposes.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ namespace Sentry
public static System.IDisposable PushScope() { }
public static System.IDisposable PushScope<TState>(TState state) { }
public static void ResumeSession() { }
public static void RunAsyncVoid(System.Action task, System.Action<System.Exception>? handler = null) { }
public static void StartSession() { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ namespace Sentry
public static System.IDisposable PushScope() { }
public static System.IDisposable PushScope<TState>(TState state) { }
public static void ResumeSession() { }
public static void RunAsyncVoid(System.Action task, System.Action<System.Exception>? handler = null) { }
public static void StartSession() { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,6 @@ namespace Sentry
public static System.IDisposable PushScope() { }
public static System.IDisposable PushScope<TState>(TState state) { }
public static void ResumeSession() { }
public static void RunAsyncVoid(System.Action task, System.Action<System.Exception>? handler = null) { }
public static void StartSession() { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }
Expand Down
1 change: 0 additions & 1 deletion test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,6 @@ namespace Sentry
public static System.IDisposable PushScope() { }
public static System.IDisposable PushScope<TState>(TState state) { }
public static void ResumeSession() { }
public static void RunAsyncVoid(System.Action task, System.Action<System.Exception>? handler = null) { }
public static void StartSession() { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context) { }
public static Sentry.ITransactionTracer StartTransaction(Sentry.ITransactionContext context, System.Collections.Generic.IReadOnlyDictionary<string, object?> customSamplingContext) { }
Expand Down

0 comments on commit 76e9f66

Please sign in to comment.