fix(app): say why an action failed in localized words, not exception text

Error toasts showed the exception's own message, often technical English from
.NET or the OS, under a translated title. The editor's failed save, a job posted
to the server from the Library, and the card check or delete after an import now
say why in one catalog sentence: what the server answered or that it does not
answer, that the card left, is locked or a file could not be read, and the
archive causes of ArchiveFailures for a local save. The details stay in the log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 10:13:34 +00:00
1 parent c11c996bc6
commit f7a7506fe7
10 files changed
+163 -5

No files matched your search

+6 -2
View File
@@ -2,6 +2,7 @@ using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Titano.App.Archiving;
using Titano.App.Infrastructure;
using Titano.App.Jobs;
using Titano.App.Server;
@@ -829,11 +830,14 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
base.OnLanguageChanged();
}
/// <summary>The first failure of a run of failed saves (they are retried until one succeeds); Retry tries at once.</summary>
/// <summary>
/// The first failure of a run of failed saves (they are retried until one succeeds); Retry tries at once. Why it
/// failed is one localized sentence (BRIEF §0.2 rule 6); the exception's own text is in the log.
/// </summary>
private void OnSaveFailed(Exception ex) => Shell.ShowToast(new Toast
{
Title = Loc.L("Editor.Save.Failed"),
Message = ex.Message,
Message = Session.IsRemote ? ErrorText.ForServer(ex) : ArchiveFailures.Cause(ex),
IsError = true,
ActionText = Loc.L("Editor.Save.Retry"),
ActionToolTip = Loc.L("Tooltips.Editor.Save.Retry"),
+27
View File
@@ -1,7 +1,9 @@
using System.IO;
using System.Net.Http;
using Titano.Core.Archiving;
using Titano.Core.Import;
using Titano.Core.Localization;
using Titano.Data;
using Titano.Protocol.Client;
namespace Titano.App.Import;
@@ -15,6 +17,7 @@ public static class ImportFailures
{
private const int DiskFull = unchecked((int)0x80070070);
private const int HandleDiskFull = unchecked((int)0x80070027);
private const int WriteProtect = unchecked((int)0x80070013);
/// <param name="source">The card or folder as the Devices list names it.</param>
public static string Import(Exception ex, string source) => ex switch
@@ -33,4 +36,28 @@ public static class ImportFailures
IOException or UnauthorizedAccessException => Loc.L("Import.Status.Unreadable", source),
_ => Loc.L("Import.Status.PlanError"),
};
/// <summary>Why the check of a card (every card file and its archive copy hashed again) stopped.</summary>
/// <param name="root">Where the card is mounted: a card that left explains any read failure.</param>
public static string Check(Exception ex, string source, string root) => ex switch
{
_ when CardGone(ex, root) => Loc.L("Import.Failed.SourceGone", source),
ArchiveOfflineException => ex.Message,
DatabaseException => Loc.L("Archive.Failed.Index"),
IOException or UnauthorizedAccessException => Loc.L("Import.Failed.CheckRead"),
_ => Loc.L("Errors.Unexpected"),
};
/// <summary>Why deleting verified photos from a card stopped.</summary>
/// <param name="root">Where the card is mounted: a card that left explains any write failure.</param>
public static string Erase(Exception ex, string source, string root) => ex switch
{
_ when CardGone(ex, root) => Loc.L("Import.Failed.SourceGone", source),
// A locked card (write-protect switch) or photos the camera marked protected (read-only).
IOException { HResult: WriteProtect } or UnauthorizedAccessException => Loc.L("Import.Failed.CardLocked", source),
_ => Loc.L("Errors.Unexpected"),
};
private static bool CardGone(Exception ex, string root) =>
ex is DirectoryNotFoundException or DriveNotFoundException or ImportSourceUnavailableException || !Directory.Exists(root);
}
@@ -177,7 +177,7 @@ public sealed class ImportResultViewModel : LocalizedViewModel
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException)
{
Log.Warning("import", "Card check failed", ex);
_shell.Notify(Loc.L("Import.Toast.CheckFailed"), ex.Message, isError: true);
_shell.Notify(Loc.L("Import.Toast.CheckFailed"), ImportFailures.Check(ex, CardName(device, device.Root), device.Root), isError: true);
}
finally
{
@@ -212,7 +212,7 @@ public sealed class ImportResultViewModel : LocalizedViewModel
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
Log.Warning("import", "Deleting imported photos failed", ex);
_shell.Notify(Loc.L("Import.Toast.DeleteFailed"), ex.Message, isError: true);
_shell.Notify(Loc.L("Import.Toast.DeleteFailed"), ImportFailures.Erase(ex, CardName(_device, erase.SourceRoot), erase.SourceRoot), isError: true);
}
finally
{
@@ -271,6 +271,9 @@ public sealed class ImportResultViewModel : LocalizedViewModel
if (outcome != FormatOutcome.Cancelled) _shell.Notify(Loc.L("Import.Toast.Format." + outcome, name), isError: outcome == FormatOutcome.Failed);
}
/// <summary>The card as a toast names it: its nickname, else its volume label, else where it is mounted.</summary>
private string CardName(CardDevice? device, string root) => _card?.Nickname ?? (string.IsNullOrEmpty(device?.Label) ? BidiText.Ltr(root) : device.Label);
/// <summary>The first files that were never imported, one per line.</summary>
private static string OtherFilesDetail(IReadOnlyList<string> files)
{
+1 -1
View File
@@ -214,7 +214,7 @@ public sealed class LibraryActions(ShellViewModel shell)
catch (Exception ex) when (ex is TitanoApiException or HttpRequestException or IOException or TaskCanceledException)
{
Log.Warning("library", $"Posting a {kind} job to {address} failed", ex);
shell.Notify(Loc.L("Library.Post.Failed"), ex.Message);
shell.Notify(Loc.L("Library.Post.Failed"), ErrorText.ForServer(ex), isError: true);
}
}
+17
View File
@@ -1,3 +1,5 @@
using System.IO;
using System.Net.Http;
using System.Reflection;
using Titano.Core.Archiving;
using Titano.Core.Import;
@@ -18,6 +20,21 @@ public static class ErrorText
{
public static string For(Exception ex) => Describe(Unwrap(ex)) ?? Loc.L("Errors.Unexpected");
/// <summary>
/// A request to the signed-in server failed: the server's own sentence when it answered, else that it does not answer
/// (refused, timed out, dropped) or that its certificate is no longer trusted.
/// </summary>
public static string ForServer(Exception ex)
{
ex = Unwrap(ex);
return Describe(ex) ?? ex switch
{
UntrustedCertificateException => Loc.L("Server.Error.Untrusted"),
HttpRequestException or IOException or OperationCanceledException or TimeoutException => Loc.L("Server.Error.Unreachable"),
_ => Loc.L("Errors.Unexpected"),
};
}
private static string? Describe(Exception ex) => ex switch
{
LeaseUnavailableException or ArchiveOfflineException or NewerFormatException or ImportSourceUnavailableException