Skip to content
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
6 changes: 2 additions & 4 deletions src/InfiniFrame.BlazorWebView/InfiniFrameBlazorApp.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ---------------------------------------------------------------------------------------------------------------------
// Imports
// ---------------------------------------------------------------------------------------------------------------------
using InfiniFrame.Utilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -62,9 +63,6 @@ public void Run() {
}
}

private static bool IsNonFatalException(Exception exception)
=> exception is not (OutOfMemoryException or AccessViolationException);

public async ValueTask DisposeAsync() {
if (_disposed) return;

Expand All @@ -87,7 +85,7 @@ public async ValueTask DisposeAsync() {
break;
}
}
catch (Exception e) when (IsNonFatalException(e)) {
catch (Exception e) when (ExceptionsUtility.IsNonFatalException(e)) {
logger?.LogError(e, "Error disposing of InfiniFrameBlazorApp");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Imports
// ---------------------------------------------------------------------------------------------------------------------
using InfiniFrame.BlazorWebView.Utils;
using InfiniFrame.Utilities;
using Microsoft.Extensions.DependencyInjection;

namespace InfiniFrame.BlazorWebView;
Expand Down Expand Up @@ -45,7 +46,7 @@ public Task InvokeAsync(Action action) {
catch (OperationCanceledException) {
completion.SetCanceled();
}
catch (Exception exception) when (IsNonFatalException(exception)) {
catch (Exception exception) when (ExceptionsUtility.IsNonFatalException(exception)) {
completion.SetException(exception);
}
}, completion);
Expand All @@ -66,7 +67,7 @@ public Task InvokeAsync(Func<Task> asyncAction) {
catch (OperationCanceledException) {
completion.SetCanceled();
}
catch (Exception exception) when (IsNonFatalException(exception)) {
catch (Exception exception) when (ExceptionsUtility.IsNonFatalException(exception)) {
completion.SetException(exception);
}
}, completion);
Expand All @@ -86,7 +87,7 @@ public Task<TResult> InvokeAsync<TResult>(Func<TResult> function) {
catch (OperationCanceledException) {
completion.SetCanceled();
}
catch (Exception exception) when (IsNonFatalException(exception)) {
catch (Exception exception) when (ExceptionsUtility.IsNonFatalException(exception)) {
completion.SetException(exception);
}
}, completion);
Expand All @@ -107,7 +108,7 @@ public Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> asyncFunction) {
catch (OperationCanceledException) {
completion.SetCanceled();
}
catch (Exception exception) when (IsNonFatalException(exception)) {
catch (Exception exception) when (ExceptionsUtility.IsNonFatalException(exception)) {
completion.SetException(exception);
}
}, completion);
Expand Down Expand Up @@ -232,7 +233,7 @@ private void ExecuteBackground(InfiniFrameSynchronizationWorkItem item) {
try {
ExecuteSynchronously(null, item.Callback, item.StateObject);
}
catch (Exception ex) when (IsNonFatalException(ex)) {
catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) {
DispatchException(ex);
}

Expand All @@ -243,7 +244,7 @@ private void ExecuteBackground(InfiniFrameSynchronizationWorkItem item) {
try {
ExecutionContext.Run(item.ExecutionContext, ExecutionContextThunk, item);
}
catch (Exception ex) when (IsNonFatalException(ex)) {
catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) {
DispatchException(ex);
}
}
Expand All @@ -252,7 +253,4 @@ private void DispatchException(Exception ex) {
UnhandledExceptionEventHandler? handler = UnhandledException;
handler?.Invoke(this, new UnhandledExceptionEventArgs(ex, false));
}

private static bool IsNonFatalException(Exception exception)
=> exception is not (OutOfMemoryException or AccessViolationException);
}
6 changes: 2 additions & 4 deletions src/InfiniFrame.BlazorWebView/InfiniFrameWebViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Imports
// ---------------------------------------------------------------------------------------------------------------------
using InfiniFrame.BlazorWebView.Utils;
using InfiniFrame.Utilities;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebView;
Expand Down Expand Up @@ -224,7 +225,7 @@ private async Task MessagePump() {
catch (OperationCanceledException) {
LazyLogger.Value?.LogDebug("WebView message pump cancellation requested.");
}
catch (Exception ex) when (IsNonFatalException(ex)) {
catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) {
LazyLogger.Value?.LogError(ex, "Unhandled exception in WebView message pump.");
throw;
}
Expand All @@ -250,9 +251,6 @@ protected override async ValueTask DisposeAsyncCore() {
}
}

private static bool IsNonFatalException(Exception exception)
=> exception is not (OutOfMemoryException or AccessViolationException);

private static string GetFallbackContentType(string localPath) {
string extension = Path.GetExtension(localPath);

Expand Down
6 changes: 2 additions & 4 deletions src/InfiniFrame.Js/Interop/RegisterWindowCreatedUtility.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ---------------------------------------------------------------------------------------------------------------------
// Imports
// ---------------------------------------------------------------------------------------------------------------------
using InfiniFrame.Utilities;
using Microsoft.Extensions.Logging;
using System.Runtime.CompilerServices;

Expand Down Expand Up @@ -76,7 +77,7 @@ IReadOnlyList<string> registrationMessages
try {
allMessagesSent = await SendRegistrationsAndAckAsync(window, registrationMessages);
}
catch (Exception ex) when (IsNonFatalException(ex)) {
catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) {
window.Logger.LogError(ex, "Unhandled error while sending window-created registration messages.");
}
finally {
Expand All @@ -96,7 +97,4 @@ private static async Task<bool> SendRegistrationsAndAckAsync(IInfiniFrameWindow
window.Logger.LogDebug("Sent '{ReadyAckMessageId}' handshake acknowledgement.", HandlerNames.WindowReadyAck);
return true;
}

private static bool IsNonFatalException(Exception exception)
=> exception is not (OutOfMemoryException or AccessViolationException);
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static T GrantBrowserPermissions<T>(this T builder, bool enable = true) w
/// The file path to the icon.
/// </value>
public static T SetIconFile<T>(this T builder, string? iconFilePath) where T : IInfiniFrameWindowBuilder {
if (!IconFileUtilities.TryResolveIconFilePath(iconFilePath, out string? resolvedIconFilePath)) return builder;
if (!IconFileUtility.TryResolveIconFilePath(iconFilePath, out string? resolvedIconFilePath)) return builder;

builder.Configuration.IconFilePath = resolvedIconFilePath;
return builder;
Expand Down
2 changes: 1 addition & 1 deletion src/InfiniFrame.Shared/FluentApi/InfiniWindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public static T SetHeight<T>(this T window, int height) where T : class, IInfini
public static T SetIconFile<T>(this T window, string iconFilePath) where T : class, IInfiniFrameWindow {
window.Logger.LogDebug(".SetIconFile({IconFile})", iconFilePath);

if (!IconFileUtilities.TryResolveIconFilePath(iconFilePath, out string? resolvedIconFilePath)) {
if (!IconFileUtility.TryResolveIconFilePath(iconFilePath, out string? resolvedIconFilePath)) {
window.Logger.LogWarning("Icon file {IconFile} does not exist or is an invalid file path.", iconFilePath);
return window;
}
Expand Down
1 change: 1 addition & 0 deletions src/InfiniFrame.Shared/InfiniFrame.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<InternalsVisibleTo Include="InfiniFrame"/>
<InternalsVisibleTo Include="InfiniFrame.WebServer"/>
<InternalsVisibleTo Include="InfiniFrame.Blazor"/>
<InternalsVisibleTo Include="InfiniFrame.BlazorWebView"/>
<InternalsVisibleTo Include="InfiniFrameTests"/>
<InternalsVisibleTo Include="InfiniFrameTests.Playwright"/>
<InternalsVisibleTo Include="InfiniFrameTests.Shared"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// ---------------------------------------------------------------------------------------------------------------------
// Imports
// ---------------------------------------------------------------------------------------------------------------------
using InfiniFrame.Native;
using InfiniFrame.Utilities;
using Microsoft.Extensions.Logging;
using System.Runtime.InteropServices;

namespace InfiniFrame.Utilities;
namespace InfiniFrame.Native;
// ---------------------------------------------------------------------------------------------------------------------
// Code
// ---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -34,7 +34,7 @@ public static bool Validate(InfiniFrameNativeParameters parameters, ILogger logg
}

if (!string.IsNullOrWhiteSpace(windowIconFile) &&
!IconFileUtilities.TryResolveIconFilePath(windowIconFile, out _)) {
!IconFileUtility.TryResolveIconFilePath(windowIconFile, out _)) {
logger.LogError("WindowIconFile: {WindowIconFile} cannot be found", windowIconFile);
result = false;
}
Expand Down
12 changes: 12 additions & 0 deletions src/InfiniFrame.Shared/Utilities/ExceptionsUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ---------------------------------------------------------------------------------------------------------------------
// Imports
// ---------------------------------------------------------------------------------------------------------------------
namespace InfiniFrame.Utilities;

// ---------------------------------------------------------------------------------------------------------------------
// Code
// ---------------------------------------------------------------------------------------------------------------------
internal static class ExceptionsUtility {
public static bool IsNonFatalException(Exception exception)
=> exception is not (OutOfMemoryException or AccessViolationException);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace InfiniFrame.Utilities;
// ---------------------------------------------------------------------------------------------------------------------
// Code
// ---------------------------------------------------------------------------------------------------------------------
public static class IconFileUtilities {
internal static class IconFileUtility {
public static bool TryResolveIconFilePath(
string? filePath,
[NotNullWhen(true)] out string? resolvedFilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace InfiniFrame.Utilities;
/// a synchronization primitive (e.g. <see cref="System.Threading.ManualResetEventSlim" />).
/// </para>
/// </summary>
internal static class InvokeUtilities {
internal static class InvokeUtility {
public static T? InvokeAndReturn<T>(IInfiniFrameWindow window, Func<IInfiniFrameWindow, T> callback) {
T? value = default;
// ReSharper disable once RedundantAssignment
Expand Down
12 changes: 12 additions & 0 deletions src/InfiniFrame.Tools.Pack/Exceptions/ExceptionsUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ---------------------------------------------------------------------------------------------------------------------
// Imports
// ---------------------------------------------------------------------------------------------------------------------
namespace InfiniFrame.Tools.Pack.Exceptions;

// ---------------------------------------------------------------------------------------------------------------------
// Code
// ---------------------------------------------------------------------------------------------------------------------
internal static class ExceptionsUtility {
public static bool IsNonFatalException(Exception exception)
=> exception is not (OutOfMemoryException or AccessViolationException);
}
5 changes: 1 addition & 4 deletions src/InfiniFrame.Tools.Pack/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@ public static async Task<int> Main(string[] args) {
Log.Error(ex, "ERROR: {Message}", ex.Message);
return ExitCodes.NativeDependencyMissing;
}
catch (Exception ex) when (IsNonFatalException(ex)) {
catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) {
Log.Error(ex, "ERROR: {Message}", ex.Message);
return ExitCodes.GenericFailure;
}
finally {
await Log.CloseAndFlushAsync();
}
}

private static bool IsNonFatalException(Exception exception)
=> exception is not (OutOfMemoryException or AccessViolationException);
}
7 changes: 3 additions & 4 deletions src/InfiniFrame.WebServer/InfiniFrameWebApplication.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// ---------------------------------------------------------------------------------------------------------------------
// Imports
// ---------------------------------------------------------------------------------------------------------------------
using InfiniFrame.Utilities;

namespace InfiniFrame.WebServer;
// ---------------------------------------------------------------------------------------------------------------------
// Code
Expand Down Expand Up @@ -89,7 +91,7 @@ private async Task StopWebAppAsync(CancellationToken ct = default) {
try {
await WebApp.StopAsync(ct);
}
catch (Exception e) when (IsNonFatalException(e)) {
catch (Exception e) when (ExceptionsUtility.IsNonFatalException(e)) {
Window.Logger.LogError(e, "Error stopping web app");
}
}
Expand All @@ -102,7 +104,4 @@ private static async Task ObserveHostRunCompletionAsync(Task runTask) {
// Host shutdown cancellation is expected.
}
}

private static bool IsNonFatalException(Exception exception)
=> exception is not (OutOfMemoryException or AccessViolationException);
}
2 changes: 1 addition & 1 deletion src/InfiniFrame/Configuration/InfiniFrameOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public string? Title {
// Methods
// -----------------------------------------------------------------------------------------------------------------
public InfiniFrameNativeParameters ToNativeParameters() {
IconFileUtilities.TryResolveIconFilePath(IconFilePath, out string? resolvedIconFilePath);
IconFileUtility.TryResolveIconFilePath(IconFilePath, out string? resolvedIconFilePath);

if (CustomSchemeNames.Count > CustomSchemeNameMemory.MaxCustomSchemeNames)
throw new InvalidOperationException("Maximum number of custom schemes is 16.");
Expand Down
8 changes: 3 additions & 5 deletions src/InfiniFrame/Events/InfiniFrameEvents.Messaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using InfiniFrame.Interop;
using InfiniFrame.Js;
using InfiniFrame.Js.Interop;
using InfiniFrame.Utilities;
using Microsoft.Extensions.Logging;
using System.Text.Json;

Expand Down Expand Up @@ -75,7 +76,7 @@ public void OnWebMessageReceived(string message, string? origin = null) {
);
}
}
catch (Exception ex) when (IsNonFatalException(ex)) {
catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) {
Sender.Logger.LogError(
ex,
"Unhandled exception while processing postMessage '{MessageId}'",
Expand All @@ -95,7 +96,7 @@ public void OnWebMessageReceived(string message, string? origin = null) {

SendSuccess(Sender, parseResult.RequestId, response);
}
catch (Exception ex) when (IsNonFatalException(ex)) {
catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) {
Sender.Logger.LogError(
ex,
"Unhandled exception while processing getMessage '{MessageId}'",
Expand All @@ -122,9 +123,6 @@ public void OnWebMessageReceived(string message, string? origin = null) {
// Helpers
// ---------------------------------------------------------------------------------------------------------------------

private static bool IsNonFatalException(Exception exception)
=> exception is not (OutOfMemoryException or AccessViolationException);

private static void SendSuccess(IInfiniFrameWindow window, string? requestId, string? data) {
string responsePayloadJson = JsonSerializer.Serialize(
new InteropGetMessageSuccessResponse {
Expand Down
Loading
Loading