-
Notifications
You must be signed in to change notification settings - Fork 14
Description
(All the interesting bugs are under NativeAOT!)
Build and run Uno.Chefs for macOS desktop under NativeAOT, which in turn requires using Uno.Sdk 6.6.0:
sed -i '' 's/"Uno.Sdk": ".*"/"Uno.Sdk": "6.6.0-dev.3"/g' global.json
dotnet publish -c Release -r osx-x64 -f net10.0-desktop -p:TargetFrameworkOverride=net10.0-desktop \
-bl Chefs/Chefs.csproj -p:UseSkiaRendering=true -p:SkiaPublishAot=true \
-p:SkiaPublishAot=true \
-p:IlcGenerateMapFile=true -p:IlcGenerateMstatFile=true -p:IlcGenerateDgmlFile=true -p:IlcGenerateMetadataLog=true \
-p:EmitCompilerGeneratedFiles=true -p:CompilerGeneratedFilesOutputPath=`pwd`/_gen
Chefs/bin/Release/net10.0-desktop/osx-x64/publish/Chefs
From the launch screen:
- Click Skip
- Click Sign in with Apple
- Click 🔍Search on the left
- In the Search box, type
m
Current behavior
The search results screen shows:
An error occurred.
The console log shows nothing.
The lack of any information about the error that occurred makes it difficult to fix the bug.
Desired behavior
The console log should show the exception that was thrown.
Implementation
For all classes underneath the Chefs.Business.Services namespace, including:
Chefs/Business/Services/Sharing/ShareService.csChefs/Business/Services/Recipes/RecipeService.csChefs/Business/Services/Users/UserService.csChefs/Business/Services/Cookbooks/CookbookService.csChefs/Business/Services/Notifications/NotificationService.cs
Perform the following changes:
-
Add an
ILogger<T> loggerconstructor parameter, in whichTis the declaring type:diff --git a/Chefs/Business/Services/Sharing/ShareService.cs b/Chefs/Business/Services/Sharing/ShareService.cs index ec38f458..0e5a6e07 100644 --- a/Chefs/Business/Services/Sharing/ShareService.cs +++ b/Chefs/Business/Services/Sharing/ShareService.cs @@ -6,7 +6,7 @@ using WinRT.Interop; namespace Chefs.Business.Services.Sharing; -public class ShareService() : IShareService +public class ShareService(ILogger<ShareService> logger) : IShareService { private Recipe? _recipe; private IImmutableList<Step>? _steps;
-
For each
publicmethod which returnsTask,Task<T>,ValueTask, orValueTask<T>, rename the method by appending aCoresuffix, and change the visibility toprivate:diff --git a/Chefs/Business/Services/Sharing/ShareService.cs b/Chefs/Business/Services/Sharing/ShareService.cs index ec38f458..fb82cef4 100644 --- a/Chefs/Business/Services/Sharing/ShareService.cs +++ b/Chefs/Business/Services/Sharing/ShareService.cs @@ -16,7 +16,7 @@ public class ShareService() : IShareService static IDataTransferManagerInterop DataTransferManagerInterop => DataTransferManager.As<IDataTransferManagerInterop>(); #endif - public async Task ShareRecipe(Recipe recipe, IImmutableList<Step> steps, CancellationToken ct) + private async Task ShareRecipeCore(Recipe recipe, IImmutableList<Step> steps, CancellationToken ct) { _recipe = recipe; _steps = steps;
-
For each method changed in (2), write a method with the original method declaration which invokes the
Coresuffixed method, wrapping the invocation in atry/catchblock. Thecatchblock should write the exception to theloggerparameter, and re-throw the exception:public async Task ShareRecipe(Recipe recipe, IImmutableList<Step> steps, CancellationToken ct) { try { await ShareRecipeCore(recipe, steps, ct); } catch (Exception ex) { logger.LogError(ex, "Failed to share recipe"); throw; } }
For example, the complete diff to ShareService is:
diff --git a/Chefs/Business/Services/Sharing/ShareService.cs b/Chefs/Business/Services/Sharing/ShareService.cs
index ec38f458..7149430e 100644
--- a/Chefs/Business/Services/Sharing/ShareService.cs
+++ b/Chefs/Business/Services/Sharing/ShareService.cs
@@ -6,7 +6,7 @@ using WinRT.Interop;
namespace Chefs.Business.Services.Sharing;
-public class ShareService() : IShareService
+public class ShareService(ILogger<ShareService> logger) : IShareService
{
private Recipe? _recipe;
private IImmutableList<Step>? _steps;
@@ -17,6 +17,19 @@ public class ShareService() : IShareService
#endif
public async Task ShareRecipe(Recipe recipe, IImmutableList<Step> steps, CancellationToken ct)
+ {
+ try
+ {
+ await ShareRecipeCore(recipe, steps, ct);
+ }
+ catch (Exception ex)
+ {
+ logger.LogError(ex, "Failed to share recipe");
+ throw;
+ }
+ }
+
+ private async Task ShareRecipeCore(Recipe recipe, IImmutableList<Step> steps, CancellationToken ct)
{
_recipe = recipe;
_steps = steps;