fix(app): keep the editor's own save errors and gate an unread archive

- Editor: a failed save showed what the server or the archive layer would say
  for the exception's type, so the editor's own sentences were lost: frames
  changed on the server or settings changed elsewhere read "The server does not
  answer", a read-only account or a gone sequence "Something went wrong". These
  failures are now EditorException (an IOException; ProxiesOutdatedException
  derives from it) and the toast shows their sentence as it is. A project
  written by a newer Titano is reported with the same sentence as a corrupt one
  instead of the parser's English text.
- Library: a job posted to a server whose certificate changed since sign-in
  threw out of the action unreported; the pin's refusal now reaches the error
  toast ("The certificate was not trusted").
- Archive: picking another archive forced it offline until it was read, so the
  rebuild dialog called it offline with the previous archive's count, and
  disabled commands said the archive must be online. What was read is now kept
  apart from availability: until the picked archive is read, Rebuild and the
  online commands wait and say so, health fixes and search results of the
  previous archive are cleared, and a running search is cancelled.

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 11:09:04 +00:00
1 parent d47e3e9b49
commit 4850af2443
15 files changed
+218 -31

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
using System.IO;
namespace Titano.App.Editor;
/// <summary>
/// A sequence the editor could not read or store, for a reason the editor words itself in one localized sentence (the
/// sequence is gone, its project cannot be read, the account may not change it, the settings kept changing elsewhere,
/// the frames changed on the server). A toast shows <see cref="Exception.Message"/> as it is (BRIEF §0.2 rule 6); any
/// other failure is mapped to a catalog sentence by its cause.
/// </summary>
public class EditorException(string message, Exception? innerException = null) : IOException(message, innerException);
+3 -2
View File
@@ -832,12 +832,13 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
/// <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.
/// failed is one localized sentence (BRIEF §0.2 rule 6): the editor's own (frames changed, changed elsewhere, gone,
/// unreadable, not allowed), else the cause on the server or in the archive; 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 = Session.IsRemote ? ErrorText.ForServer(ex) : ArchiveFailures.Cause(ex),
Message = ex is EditorException ? ex.Message : Session.IsRemote ? ErrorText.ForServer(ex) : ArchiveFailures.Cause(ex),
IsError = true,
ActionText = Loc.L("Editor.Save.Retry"),
ActionToolTip = Loc.L("Tooltips.Editor.Save.Retry"),
+2 -1
View File
@@ -41,7 +41,7 @@ public interface ISequenceSource : IAsyncDisposable
event Action<Job>? JobChanged;
/// <summary>Everything the editor shows of the sequence; read off the UI thread.</summary>
/// <exception cref="InvalidDataException">The project cannot be read (corrupt, or written by a newer Titano).</exception>
/// <exception cref="EditorException">The sequence is gone, or its project cannot be read (corrupt, or written by a newer Titano).</exception>
Task<SequenceContent> LoadAsync(CancellationToken cancellationToken);
/// <summary>
@@ -55,6 +55,7 @@ public interface ISequenceSource : IAsyncDisposable
/// change made meanwhile by someone else is kept where this edit left the value alone (<see cref="ProjectMerge"/>).
/// Returns the stored project.
/// </summary>
/// <exception cref="EditorException">The editor's own reason the project was not stored, worded for the user.</exception>
Task<ProjectSettings> SaveProjectAsync(ProjectSettings project, ProjectSettings basis, CancellationToken cancellationToken);
/// <summary>Queues an analysis or render job for the sequence; returns the job id.</summary>
+5 -5
View File
@@ -146,7 +146,7 @@ public sealed class LocalSequenceSource : ISequenceSource
throw Missing();
// The settings moved in the index meanwhile (server API): merge again on top of them; the file follows the next write.
case SequenceEditOutcome.Conflict when attempt == SaveAttempts:
throw new IOException(Loc.L("Editor.Error.SaveConflict"));
throw new EditorException(Loc.L("Editor.Error.SaveConflict"));
}
}
}, cancellationToken);
@@ -175,7 +175,7 @@ public sealed class LocalSequenceSource : ISequenceSource
}
/// <summary>The settings in force: the index copy, else <c>project.json</c>, else defaults.</summary>
/// <exception cref="InvalidDataException">The settings are not a project or come from a newer Titano.</exception>
/// <exception cref="EditorException">The settings are not a project or come from a newer Titano.</exception>
internal static ProjectSettings ReadProject(Sequence sequence, SequencePaths folder)
{
var json = sequence.SettingsJson ?? (File.Exists(folder.ProjectPath) ? File.ReadAllText(folder.ProjectPath) : null);
@@ -184,9 +184,9 @@ public sealed class LocalSequenceSource : ISequenceSource
{
return ProjectSettings.FromJson(json);
}
catch (JsonException ex)
catch (Exception ex) when (ex is JsonException or InvalidDataException)
{
throw new InvalidDataException(Loc.L("Editor.Error.Project"), ex);
throw new EditorException(Loc.L("Editor.Error.Project"), ex);
}
}
@@ -212,5 +212,5 @@ public sealed class LocalSequenceSource : ISequenceSource
private void OnJobChanged(Job job) => JobChanged?.Invoke(job);
private static InvalidOperationException Missing() => new(Loc.L("Editor.Error.Missing"));
private static EditorException Missing() => new(Loc.L("Editor.Error.Missing"));
}
@@ -145,7 +145,7 @@ public sealed class RemoteSequenceSource : ISequenceSource
var merged = changedThere ? ProjectMerge.Merge(basis, project, stored) : project;
if (ProjectMerge.SameValues(merged, stored)) return merged;
if (IsOutdated) throw new ProxiesOutdatedException(Loc.L("Editor.Error.FramesChanged"));
if (_noEditRight) throw new InvalidOperationException(Loc.L("Editor.Error.RemoteReadOnly"));
if (_noEditRight) throw new EditorException(Loc.L("Editor.Error.RemoteReadOnly"));
if (changedThere && ProjectMerge.Conflicts(basis, project, stored) is { Count: > 0 } conflicts)
throw new ProjectConflictException(Loc.L("Editor.Error.SaveConflict"), stored, conflicts);
var hero = merged.HeroFrame == stored.HeroFrame ? (Guid?)null : HeroFrameId(merged);
@@ -159,7 +159,7 @@ public sealed class RemoteSequenceSource : ISequenceSource
catch (TitanoApiException ex) when (ex.Status == HttpStatusCode.Conflict)
{
// Changed on the server since this editor read it: merge again on top of the server's settings.
if (attempt == SaveAttempts) throw new IOException(Loc.L("Editor.Error.SaveConflict"), ex);
if (attempt == SaveAttempts) throw new EditorException(Loc.L("Editor.Error.SaveConflict"), ex);
var manifest = await Call(() => _api.GetManifestAsync(Id, cancellationToken));
if (!SameFrames(manifest)) throw Outdated();
Volatile.Write(ref _stored, new Stored(Parse(manifest.SettingsJson), manifest.SettingsVersion));
@@ -359,7 +359,7 @@ public sealed class RemoteSequenceSource : ISequenceSource
private Guid HeroFrameId(ProjectSettings project) =>
project.HeroFrame is { } hero && (uint)hero < (uint)_remote.Frames.Count ? _remote.Frames[hero].Id : Guid.Empty;
/// <exception cref="InvalidDataException">The settings are not a project or come from a newer Titano.</exception>
/// <exception cref="EditorException">The settings are not a project or come from a newer Titano.</exception>
private static ProjectSettings Parse(string? json)
{
if (string.IsNullOrWhiteSpace(json)) return new ProjectSettings();
@@ -367,9 +367,9 @@ public sealed class RemoteSequenceSource : ISequenceSource
{
return ProjectSettings.FromJson(json);
}
catch (JsonException ex)
catch (Exception ex) when (ex is JsonException or InvalidDataException)
{
throw new InvalidDataException(Loc.L("Editor.Error.Project"), ex);
throw new EditorException(Loc.L("Editor.Error.Project"), ex);
}
}
@@ -398,7 +398,7 @@ public sealed class RemoteSequenceSource : ISequenceSource
}
catch (TitanoApiException ex) when (ex.Status == HttpStatusCode.NotFound)
{
throw new InvalidOperationException(Loc.L("Editor.Error.Missing"), ex);
throw new EditorException(Loc.L("Editor.Error.Missing"), ex);
}
}
@@ -423,4 +423,4 @@ public sealed class ProjectConflictException(string message, ProjectSettings ser
/// The proxies of a server sequence are for frames the server no longer has (added or removed since they were fetched):
/// they must be fetched again before the sequence can be edited.
/// </summary>
public sealed class ProxiesOutdatedException(string message) : IOException(message);
public sealed class ProxiesOutdatedException(string message) : EditorException(message);
+2 -1
View File
@@ -211,7 +211,8 @@ public sealed class LibraryActions(ShellViewModel shell)
await client.CreateJobAsync(request);
shell.Notify(Loc.L("Library.QueuedServer", JobText.Kind(kind), label));
}
catch (Exception ex) when (ex is TitanoApiException or HttpRequestException or IOException or TaskCanceledException)
// A certificate the server changed since sign-in is refused by the pin, not by the network (UntrustedCertificateException).
catch (Exception ex) when (ex is TitanoApiException or HttpRequestException or IOException or TaskCanceledException or UntrustedCertificateException)
{
Log.Warning("library", $"Posting a {kind} job to {address} failed", ex);
shell.Notify(Loc.L("Library.Post.Failed"), ErrorText.ForServer(ex), isError: true);
+29 -9
View File
@@ -46,6 +46,10 @@ public sealed class ArchiveViewModel : SectionViewModel
private IReadOnlyList<Core.Model.Archive> _archives = [];
private Core.Model.Archive? _archive;
private ArchiveAvailability _availability = ArchiveAvailability.Offline;
/// <summary>The archive whose availability, figures and tree were read last: until it is the picked one, nothing acts on them.</summary>
private Guid? _readId;
private ArchiveStats? _stats;
private int _withoutProxies;
private ArchiveTree? _tree;
@@ -79,7 +83,7 @@ public sealed class ArchiveViewModel : SectionViewModel
_ = LoadAsync();
};
ScanCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Scan(a)), IsOnline);
RebuildCommand = new AsyncRelayCommand(() => OpenRebuildDialogAsync(), () => _archive is not null);
RebuildCommand = new AsyncRelayCommand(() => OpenRebuildDialogAsync(), IsRead);
VerifyCommand = new AsyncRelayCommand(() => QueueAsync(a => ArchiveJobs.Verify(a)), IsOnline);
AdoptCommand = new AsyncRelayCommand(AdoptAsync);
CopyFolderCommand = new RelayCommand(CopyFolder, () => _archive is not null);
@@ -128,11 +132,15 @@ public sealed class ArchiveViewModel : SectionViewModel
_orphans = null;
if (other)
{
// Until the picked archive is read, nothing of the previous one stays actionable: no tree to take a set
// from, no availability to allow a scan.
// Until the picked archive is read (IsRead), nothing of the previous one stays actionable: no tree to take
// a set from, no availability to allow a scan, no figures for the rebuild dialog or the health fixes, no
// search results. The tooltips say the archive is being read.
_search?.Cancel();
_tree = null;
_availability = ArchiveAvailability.Offline;
_stats = null;
_health = [];
RebuildRows();
OnPropertyChanged(string.Empty);
CommandManager.InvalidateRequerySuggested();
}
_ = LoadAsync();
@@ -425,6 +433,7 @@ public sealed class ArchiveViewModel : SectionViewModel
if (!IsShowing(archive)) return;
_availability = availability;
_stats = stats;
_readId = archive.Id;
ShowFigures(stats, withoutProxies);
ShowTree(ArchiveTree.Build(archive, availability, sequences));
await LoadRecentAsync(db, archive);
@@ -444,7 +453,7 @@ public sealed class ArchiveViewModel : SectionViewModel
/// <summary>Opens the rebuild dialog (BRIEF §12.5) and counts, off the UI thread, the sidecars the rebuild will read.</summary>
public async Task<RebuildDialogViewModel?> OpenRebuildDialogAsync()
{
if (_archive is not { } archive || Services.Engine is not { } engine) return null;
if (_archive is not { } archive || !IsRead() || Services.Engine is not { } engine) return null;
var dialog = new RebuildDialogViewModel(archive, _availability, _stats?.Sequences ?? 0, async () =>
{
var request = ArchiveJobs.Rebuild(archive);
@@ -649,13 +658,19 @@ public sealed class ArchiveViewModel : SectionViewModel
// ---------------- Actions ----------------
private bool IsOnline() => _archive is not null && _availability == ArchiveAvailability.Online;
private bool IsOnline() => IsRead() && _availability == ArchiveAvailability.Online;
/// <summary>The picked archive's availability and figures are known (a slow volume is probed for seconds).</summary>
private bool IsRead() => _archive is { } archive && _readId == archive.Id;
/// <summary>The archive a read started with is still the one picked.</summary>
private bool IsShowing(Core.Model.Archive archive) => _archive?.Id == archive.Id;
/// <summary>A command's tooltip, or why it is disabled: these commands write to the archive or read all of it.</summary>
private string WhenOnline(string key) => _archive is null || IsOnline() ? Loc.L(key) : Loc.L("Archive.Blocked.NotOnline");
private string WhenOnline(string key) =>
_archive is null || IsOnline() ? Loc.L(key)
: !IsRead() ? Loc.L("Archive.Blocked.Reading")
: Loc.L("Archive.Blocked.NotOnline");
private bool HasSet() => _archive is not null && _tree is not null && Set().Count > 0;
@@ -853,7 +868,10 @@ public sealed class ArchiveViewModel : SectionViewModel
try
{
var groups = await Task.Run(() => archives.FindDuplicatesAsync(archive.Id, search.Token), search.Token);
Duplicates = DuplicateRows(groups, await db.Sequences.ListLocationsAsync(archive.Id, search.Token));
var locations = await db.Sequences.ListLocationsAsync(archive.Id, search.Token);
// Picking another archive cancels the search; one that ended just then is not the picked archive's.
if (!IsShowing(archive)) return;
Duplicates = DuplicateRows(groups, locations);
Log.Info("archive", $"Duplicates search in {archive.RootPath}: {groups.Count} group(s)");
}
catch (OperationCanceledException) when (search.IsCancellationRequested)
@@ -881,7 +899,9 @@ public sealed class ArchiveViewModel : SectionViewModel
try
{
var report = await Task.Run(() => archives.FindOrphansAsync(archive.Id, search.Token), search.Token);
Orphans = OrphanRows(report, await db.Sequences.ListLocationsAsync(archive.Id, search.Token));
var locations = await db.Sequences.ListLocationsAsync(archive.Id, search.Token);
if (!IsShowing(archive)) return;
Orphans = OrphanRows(report, locations);
Log.Info("archive", $"Orphans search in {archive.RootPath}: {report.UnindexedFiles} unlisted, {report.MissingFiles} missing, "
+ $"{report.MissingSequences.Count} rows without sidecar, {report.UnindexedFolders.Count} new folders");
}