Skip to content

bug(app): Fire-and-forget InitialiseAsync + missing UnobservedTaskException handler in App.axaml.cs #47

Description

@jaybarden1

Problem

App.axaml.cs has two startup reliability defects:

1. Fire-and-forget InitialiseAsync

Line 46: _ = InitialiseAsync(_serviceProvider, viewModel);

If MigrateAsync or LoadPersistedAccountsAsync throws, the exception is unobserved and silently discarded. The app will appear to start normally but with no accounts loaded and no migration applied.

Fix — attach an explicit error-surfacing continuation:

_ = InitialiseAsync(_serviceProvider, viewModel)
    .ContinueWith(t =>
    {
        if (t.Exception is { } ex)
        {
            LogStartupFailed(_logger, ex.Message);
            Dispatcher.UIThread.InvokeAsync(() =>
            {
                viewModel.HasError = true;
                viewModel.ErrorMessage = "Startup failed. Please restart the application.";
            });
        }
    }, TaskScheduler.Default);

2. Missing TaskScheduler.UnobservedTaskException handler

onedrive-di.md requires a top-level unhandled exception handler:

TaskScheduler.UnobservedTaskException += (_, args) =>
{
    LogUnhandledException(_logger, args.Exception);
    args.SetObserved();
    RxApp.MainThreadScheduler.Schedule(() =>
    {
        viewModel.HasError = true;
        viewModel.ErrorMessage = "An unexpected error occurred. Please restart the application.";
    });
};

Without this, unobserved exceptions from any async operation silently crash the task.

Rule reference

@.claude/rules/onedrive-di.md — Unhandled exceptions section

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstartup

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions