Skip to content
Open
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
16 changes: 16 additions & 0 deletions integration-test/ios.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Describe 'iOS app (<tfm>, <configuration>, <runtime>)' -ForEach @(

Remove-Item -Path "$PSScriptRoot/mobile-app" -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item -Path "$PSScriptRoot/net9-maui" -Destination "$PSScriptRoot/mobile-app" -Recurse -Force
# clean up potential old copied build outputs that may target a different configuration or runtime
Remove-Item -Path "$PSScriptRoot/mobile-app/bin", "$PSScriptRoot/mobile-app/obj" `
-Recurse -Force -ErrorAction SilentlyContinue
Push-Location $PSScriptRoot/mobile-app

$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower()
Expand Down Expand Up @@ -107,6 +110,19 @@ Describe 'iOS app (<tfm>, <configuration>, <runtime>)' -ForEach @(
$result.Envelopes() | Should -HaveCount 1
}

It 'does not leak managed exception as NSException (<configuration>, <runtime>)' {
$result = Invoke-SentryServer {
param([string]$url)
RunIosApp -Dsn $url -TestArg "OnActivated"
RunIosApp -Dsn $url
}

$result.HasErrors() | Should -BeFalse
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`""
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"nsexception`""
$result.Envelopes() | Should -HaveCount 1
}
Comment thread
sentry-warden[bot] marked this conversation as resolved.

It 'captures native crash (<configuration>, <runtime>)' {
$result = Invoke-SentryServer {
param([string]$url)
Expand Down
10 changes: 10 additions & 0 deletions integration-test/net9-maui/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ protected override Window CreateWindow(IActivationState? activationState)
return new Window(new AppShell());
}

public static void OnActivated()
{
testArg = System.Environment.GetEnvironmentVariable("SENTRY_TEST_ARG");

if (HasTestArg("OnActivated"))
{
throw new ApplicationException("This exception was thrown deliberately from AppDelegate.OnActivated.");
}
}
Comment thread
sentry-warden[bot] marked this conversation as resolved.

public static void OnAppearing()
{
testArg = System.Environment.GetEnvironmentVariable("SENTRY_TEST_ARG");
Expand Down
7 changes: 7 additions & 0 deletions integration-test/net9-maui/Platforms/iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using Foundation;
using UIKit;

namespace Sentry.Maui.Device.IntegrationTestApp;

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

public override void OnActivated(UIApplication application)
{
base.OnActivated(application);
App.OnActivated();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ internal void Handle(object sender, MarshalManagedExceptionEventArgs e)
return;
}

e.ExceptionMode = MarshalManagedExceptionMode.Abort;

// Otherwise the runtime will call abort() after we return — directly via
// xamarin_assertion_message, or indirectly via the uncaught-NSException handler for
// ThrowObjectiveCException. Tell SentryCrash to ignore that SIGABRT so we don't emit a
// xamarin_assertion_message. Tell SentryCrash to ignore that SIGABRT so we don't emit a
// duplicate native crash for an exception we've already captured. See
// https://github.com/dotnet/macios/blob/be8a2ca1057242f745ef58011a02ffe21326d180/runtime/runtime.m#L2285
const int SIGABRT = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ public void Handle_Mono_AbortingMode_IgnoresSigabrt(MarshalManagedExceptionMode
_fixture.Runtime.Received(1).IgnoreNextSignal(6);
}

[Fact]
public void Handle_ThrowObjectiveCException_ChangesModeToAbort()
{
var sut = _fixture.GetSut();
sut.Register(_fixture.Hub, SentryOptions);
var args = new MarshalManagedExceptionEventArgs { Exception = new Exception(), ExceptionMode = MarshalManagedExceptionMode.ThrowObjectiveCException };

sut.Handle(this, args);

Assert.Equal(MarshalManagedExceptionMode.Abort, args.ExceptionMode);
}

[Theory]
[InlineData(MarshalManagedExceptionMode.Disable)]
[InlineData(MarshalManagedExceptionMode.UnwindNativeCode)]
Expand Down
Loading