fix(import): staging failures of a server import name this PC, failed jobs show catalog sentences

A server import stages its copies in this PC's cache folder, yet a full disk
there read 'The destination is full.' beside every photo, and a refused
write 'Titano may not write to the destination.', which sent the user to
the server. IImportSink.StagesOnThisPc (true for ServerImportSink) selects
Import.Failed.CacheFull and Import.Failed.CacheAccess instead.

A failed archive import job showed the job engine's raw text (SQLite, file
system or framework English) as the Import screen's line. ImportFailures.Job
keeps the archive engine's own localized sentences and shows 'The import
stopped before the end.' for anything else; the raw text stays in the
tooltip and the logs.

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 19:00:51 +00:00
1 parent 59d49f16af
commit e97b0e4f84
9 files changed
+100 -9

No files matched your search

+1 -1
View File
@@ -233,7 +233,7 @@ public static class LocalImport
catch (Exception ex) when (!cancellationToken.IsCancellationRequested && Stops(ex))
{
Log.Warning("import", $"Import into {plan.DestinationRoot} stopped", ex);
stopped = ImportFailures.Stop(ex, source);
stopped = ImportFailures.Stop(ex, source, sink.StagesOnThisPc);
}
return ImportOutcome.From(plan, results, verify, report, stopped);
}
+30 -2
View File
@@ -1,5 +1,6 @@
using System.IO;
using System.Net.Http;
using System.Text.RegularExpressions;
using Titano.App.Shell;
using Titano.Core.Archiving;
using Titano.Core.Import;
@@ -20,6 +21,13 @@ public static class ImportFailures
private const int HandleDiskFull = unchecked((int)0x80070027);
private const int WriteProtect = unchecked((int)0x80070013);
/// <summary>The sentences an archive import job fails with when the archive's engine stops it itself.</summary>
private static readonly string[] EngineSentences =
[
"Archive.Error.Offline", "Archive.Error.ReadOnly", "Archive.Error.Busy", "Archive.Error.NewerFormat", "Archive.Error.SourceGone",
"Archive.Error.DuplicateLost",
];
/// <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,14 +41,26 @@ public static class ImportFailures
/// <summary>
/// Why the photos an import into a folder or the server never reached were not copied (<see cref="LocalImport"/>):
/// the card left, the destination is full or refuses writing, or the server answered with its own sentence, does
/// not answer (a timeout too) or is no longer trusted.
/// not answer (a timeout too) or is no longer trusted. When the sink stages on this PC (<paramref name="stagesOnThisPc"/>,
/// the server's), a full disk or a refused write is this PC's cache folder's: the server answers for its own space.
/// </summary>
public static string Stop(Exception ex, string source) => ex switch
public static string Stop(Exception ex, string source, bool stagesOnThisPc = false) => ex switch
{
TitanoApiException or HttpRequestException or UntrustedCertificateException or OperationCanceledException => ErrorText.ForServer(ex),
IOException { HResult: DiskFull or HandleDiskFull } when stagesOnThisPc => Loc.L("Import.Failed.CacheFull"),
UnauthorizedAccessException when stagesOnThisPc => Loc.L("Import.Failed.CacheAccess"),
_ => Import(ex, source),
};
/// <summary>
/// What a failed archive import job says, from the text the job engine kept of what stopped it: the engine's own
/// sentence (archive offline, read-only or busy, a newer format, the card gone, a photo it could not add) in the
/// language shown now, else 'The import stopped before the end.' Framework, database and system text goes to the
/// tooltip and the logs only.
/// </summary>
public static string Job(string? error) =>
error is { Length: > 0 } && EngineSentences.Any(key => IsSentence(key, error)) ? error : Loc.L("Import.Failed.Other");
/// <summary>Why the card or folder could not be planned.</summary>
public static string Plan(Exception ex, string source) => ex switch
{
@@ -70,6 +90,14 @@ public static class ImportFailures
_ => Loc.L("Errors.Unexpected"),
};
/// <summary>Whether <paramref name="text"/> is the sentence of <paramref name="key"/>, whatever its arguments.</summary>
private static bool IsSentence(string key, string text)
{
const string Argument = "\u0001";
var pattern = Regex.Escape(Loc.L(key, Argument, Argument)).Replace(Argument, ".+", StringComparison.Ordinal);
return Regex.IsMatch(text, "^" + pattern + "$", RegexOptions.CultureInvariant | RegexOptions.Singleline);
}
private static bool CardGone(Exception ex, string root) =>
ex is DirectoryNotFoundException or DriveNotFoundException or ImportSourceUnavailableException || !Directory.Exists(root);
}
@@ -24,6 +24,9 @@ public sealed class ServerImportSink(TitanoClient client, string stagingDirector
public string StagingDirectory { get; } = stagingDirectory;
/// <summary>The copies wait in this PC's cache folder until they are uploaded: the server's space is its quota.</summary>
public bool StagesOnThisPc => true;
/// <summary>Every file committed or refused so far, by card path; pass it to <see cref="LocalImport.RunAsync"/>.</summary>
public ImportSinkReport Report { get; } = new();
+3 -2
View File
@@ -1279,8 +1279,9 @@ public sealed class ImportViewModel : SectionViewModel
await QueueDeepAnalysisAsync(plan);
break;
case JobState.Failed:
// The engine wrote the job's error (a localized sentence for the archive's own failures); the full text stays in the tooltip.
Fail(job.Error ?? Loc.L("Import.Failed.Other"), job.Error);
// The engine kept the text of what stopped the job: the archive's own failures are localized sentences, anything
// else reads as the catalog's and its text stays in the tooltip.
Fail(ImportFailures.Job(job.Error), job.Error);
break;
case JobState.Cancelled:
_jobId = null;
+11 -4
View File
@@ -27,6 +27,12 @@ public interface IImportSink
/// <summary>Folder for verified copies, on the destination volume so commits are renames.</summary>
string StagingDirectory { get; }
/// <summary>
/// True when <see cref="StagingDirectory"/> lies on this PC rather than at the destination (a server import stages its
/// copies in this PC's cache folder): a full disk or a refused write while staging then concerns this PC.
/// </summary>
bool StagesOnThisPc => false;
/// <summary>Moves staged files of one session into place; returns one result per file, in order. Files it does
/// not move stay where they are and the executor deletes them.</summary>
Task<IReadOnlyList<SinkCommit>> CommitAsync(PlannedSession session, IReadOnlyList<StagedFile> files, CancellationToken cancellationToken);
@@ -138,7 +144,7 @@ public sealed class ImportExecutor(ImportPlan plan, IImportSink sink)
}
Log.Warning("import", $"Copy of {item.SourcePath} failed", ex);
failed++;
results.Add(new ImportItemResult(session, item, ImportItemStatus.Failed, null, null, FailureText(ex)));
results.Add(new ImportItemResult(session, item, ImportItemStatus.Failed, null, null, FailureText(ex, sink.StagesOnThisPc)));
}
}
await FlushAsync().ConfigureAwait(false);
@@ -148,13 +154,14 @@ public sealed class ImportExecutor(ImportPlan plan, IImportSink sink)
/// <summary>
/// Why one photo was not copied, as one localized sentence (BRIEF §0.2 rule 6): the Import screen lists it beside the
/// photo and the import job writes it to its log. The executor's own checks say what they found; the operating
/// system's text, technical English, goes to the application log only.
/// system's text, technical English, goes to the application log only. A full disk is the staging folder's: the
/// destination's, or this PC's when the sink stages there (<paramref name="stagesOnThisPc"/>).
/// </summary>
internal static string FailureText(Exception ex) => ex switch
internal static string FailureText(Exception ex, bool stagesOnThisPc = false) => ex switch
{
// Already one localized sentence each.
ImportSourceChangedException or CopyVerificationException => ex.Message,
IOException { HResult: DiskFull or HandleDiskFull } => Loc.L("Import.Failed.Full"),
IOException { HResult: DiskFull or HandleDiskFull } => Loc.L(stagesOnThisPc ? "Import.Failed.CacheFull" : "Import.Failed.Full"),
UnauthorizedAccessException => Loc.L("Import.Failed.PhotoAccess"),
_ => Loc.L("Import.Failed.Photo"),
};