Files
h-school/src/HSchool.Content/PackDependencyException.cs
T

33 lines
1.0 KiB
C#

namespace HSchool.Content;
/// <summary>
/// Selected packs cannot be ordered: a required pack is missing, or they require each other.
/// Distinct from <see cref="ContentLoadException"/> so the create dialog can name the pack.
/// </summary>
public sealed class PackDependencyException : Exception
{
public const string MissingCode = "missing-mod";
public const string CycleCode = "mod-cycle";
private PackDependencyException(string message, string code, string? missingPackId)
: base(message)
{
Code = code;
MissingPackId = missingPackId;
}
public string Code { get; }
public string? MissingPackId { get; }
public static PackDependencyException Missing(string missingPackId, string requiredBy) =>
new(
$"Pack '{requiredBy}' requires '{missingPackId}', which was not selected.",
MissingCode,
missingPackId);
public static PackDependencyException Cycle() =>
new("Selected packs have a cyclic dependency.", CycleCode, missingPackId: null);
}