Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed RunAsyncVoid method #3466

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading