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:
10 files changed
+163
-5
No files matched your search
@@ -1,4 +1,6 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.Net.Http;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
@@ -251,6 +253,35 @@ public sealed class EditorSmokeTests
|
||||
Assert.False(viewer.OptimiseAllCommand.CanExecute(null));
|
||||
Assert.False(viewer.AnalyseCommand.CanExecute(null));
|
||||
}
|
||||
|
||||
// A failed save says why in one localized sentence (BRIEF §0.2 rule 6); the exception's own text stays in the log.
|
||||
var toasts = new List<Toast>();
|
||||
NotifyCollectionChangedEventHandler collect = (_, e) => toasts.AddRange(e.NewItems?.OfType<Toast>() ?? []);
|
||||
shell.PendingToasts.CollectionChanged += collect;
|
||||
try
|
||||
{
|
||||
foreach (var (remote, failure, cause) in new (bool, Exception, string)[]
|
||||
{
|
||||
(true, new HttpRequestException("No such host is known."), "Server.Error.Unreachable"),
|
||||
(false, new UnauthorizedAccessException(@"Access to the path 'D:\Archive\.titano\sequence.json' is denied."), "Archive.Failed.Access"),
|
||||
})
|
||||
{
|
||||
toasts.Clear();
|
||||
var saving = new FakeSequenceSource(EditorFixture.Sunset, content) { IsRemote = remote, FailNextSave = failure };
|
||||
var failing = new EditorViewModel(shell, new EditorSession(saving, content, []), [], EncoderHost.Client);
|
||||
await using (failing)
|
||||
{
|
||||
failing.Session.Edit(p => p with { HeroFrame = 1 });
|
||||
Assert.False(await failing.Session.FlushAsync(), "the save failed");
|
||||
var toast = Assert.Contains(toasts, t => t.Title == Loc.L("Editor.Save.Failed"));
|
||||
Assert.Equal(Loc.L(cause), toast.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
shell.PendingToasts.CollectionChanged -= collect;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -3,8 +3,10 @@ using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Titano.App.Import;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Data;
|
||||
using Titano.Protocol;
|
||||
using Titano.Protocol.Client;
|
||||
using Titano.Testing;
|
||||
@@ -38,4 +40,31 @@ public sealed class ImportFailuresTests
|
||||
Assert.Equal(@"D:\Shoots could not be read.", ImportFailures.Plan(new IOException("The device is not ready."), Folder));
|
||||
Assert.Equal("The import could not be planned.", ImportFailures.Plan(new InvalidOperationException("Sequence contains no elements"), Folder));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ACardCheckOrDeleteFailureIsOneSentenceByCause()
|
||||
{
|
||||
const string Card = "EOS R5 · card A";
|
||||
var root = Directory.CreateTempSubdirectory("titano-card-").FullName;
|
||||
try
|
||||
{
|
||||
Assert.Equal("A photo or its archive copy could not be read.", ImportFailures.Check(new IOException("The semaphore timeout period has expired."), Card, root));
|
||||
Assert.Equal("The index could not be read or written.", ImportFailures.Check(new DatabaseConnectionException("database is locked"), Card, root));
|
||||
Assert.Equal("The archive D:\\Shoots is offline.", ImportFailures.Check(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.Offline), Card, root));
|
||||
Assert.Equal("Something went wrong.", ImportFailures.Check(new InvalidOperationException("Collection was modified."), Card, root));
|
||||
Assert.Equal("EOS R5 · card A is write-protected or holds protected photos.",
|
||||
ImportFailures.Erase(new IOException("The media is write protected.", unchecked((int)0x80070013)), Card, root));
|
||||
Assert.Equal("EOS R5 · card A is write-protected or holds protected photos.",
|
||||
ImportFailures.Erase(new UnauthorizedAccessException(@"Access to the path 'E:\DCIM\IMG_0001.CR3' is denied."), Card, root));
|
||||
Assert.Equal("Something went wrong.", ImportFailures.Erase(new IOException("The request could not be performed because of an I/O device error."), Card, root));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Directory.Delete(root);
|
||||
}
|
||||
// A card that left explains whatever failed while it was read or written.
|
||||
var gone = Path.Combine(Path.GetTempPath(), "titano-card-" + Guid.NewGuid().ToString("N"));
|
||||
Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Check(new IOException("The device is not ready."), Card, gone));
|
||||
Assert.Equal("EOS R5 · card A is no longer available.", ImportFailures.Erase(new UnauthorizedAccessException("Access denied."), Card, gone));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Titano.App.Shell;
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Protocol;
|
||||
using Titano.Protocol.Client;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.App.Tests.Infrastructure;
|
||||
|
||||
/// <summary>An error toast says what happened in one localized sentence; framework and OS messages stay in the log.</summary>
|
||||
public sealed class ErrorTextTests
|
||||
{
|
||||
public ErrorTextTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
|
||||
[Test]
|
||||
public void AServerFailureIsTheServersSentenceOrThatItDoesNotAnswer()
|
||||
{
|
||||
const string Unreachable = "The server does not answer; check the address and the network.";
|
||||
Assert.Equal("The server is out of disk space.",
|
||||
ErrorText.ForServer(new TitanoApiException(HttpStatusCode.InsufficientStorage, new ApiError("insufficient_storage", "The server is out of disk space.", null))));
|
||||
Assert.Equal(Unreachable, ErrorText.ForServer(new HttpRequestException("No such host is known. (nas.local:8443)")));
|
||||
Assert.Equal(Unreachable, ErrorText.ForServer(new TaskCanceledException("A task was canceled.")));
|
||||
Assert.Equal(Unreachable, ErrorText.ForServer(new IOException("The response ended prematurely.")));
|
||||
Assert.Equal(Unreachable, ErrorText.ForServer(new AggregateException(new HttpRequestException("Connection refused"))));
|
||||
Assert.Equal("The certificate was not trusted, so nothing was sent.", ErrorText.ForServer(new UntrustedCertificateException("AB:CD")));
|
||||
// Failures that already carry a catalog sentence keep it.
|
||||
Assert.Equal(@"The archive D:\Shoots is offline.", ErrorText.ForServer(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.Offline)));
|
||||
Assert.Equal("Something went wrong.", ErrorText.ForServer(new InvalidOperationException("Sequence contains no elements")));
|
||||
Assert.Equal("Something went wrong.", ErrorText.ForServer(new TitanoApiException(HttpStatusCode.BadGateway, new ApiError("bad_gateway", " ", null))));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnyOtherFailureNeverShowsTheFrameworkText()
|
||||
{
|
||||
Assert.Equal("Something went wrong.", ErrorText.For(new HttpRequestException("No such host is known.")));
|
||||
Assert.Equal("Something went wrong.", ErrorText.For(new IOException(@"Access to the path 'D:\Archive' is denied.")));
|
||||
Assert.Equal(@"The archive D:\Shoots is read-only.", ErrorText.For(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.ReadOnly)));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user