Path: redb/redb.Core/Exceptions/RedbRenameConflictException.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Exceptions/RedbRenameConflictException.cs
----
namespace redb.Core.Exceptions;
///
/// Thrown by the scheme sync when a rename cannot be applied without losing stored values, or when the class being
/// synchronised predates a rename the database has already seen. Thrown before anything is written for the field;
/// the sync of the scheme stops.
///
public class RedbRenameConflictException : Exception
{
/// The scheme the conflict is in.
public string SchemeName { get; }
/// The name the class declares: a property name, or the scheme name for a scheme rename.
public string Name { get; }
/// The other stored names involved in the conflict.
public IReadOnlyList StoredNames { get; }
private RedbRenameConflictException(string message, string schemeName, string name, IReadOnlyList storedNames)
: base(message)
{
SchemeName = schemeName;
Name = name;
StoredNames = storedNames;
}
/// The property and one of its previous names are both stored: each may hold values.
internal static RedbRenameConflictException BothStored(string schemeName, string propertyPath, string oldName,
long id, long oldId)
=> new($"Scheme '{schemeName}': property '{propertyPath}' declares [RedbRename(\"{oldName}\")], but the " +
$"database stores both '{propertyPath}' (structure {id}) and '{oldName}' (structure {oldId}). " +
"Renaming would lose the values of one of them. Move the values to one structure and delete the " +
"other by hand, then start again.",
schemeName, propertyPath, [oldName]);
/// More than one stored property matches the previous names of one property.
internal static RedbRenameConflictException SeveralStored(string schemeName, string propertyPath,
IReadOnlyList<(string Name, long Id)> stored)
=> new($"Scheme '{schemeName}': property '{propertyPath}' has more than one stored previous name: " +
string.Join(", ", stored.Select(s => $"'{s.Name}' (structure {s.Id})")) +
". Renaming one of them would leave the others to the sync. Keep one structure and delete the " +
"others by hand, then start again.",
schemeName, propertyPath, stored.Select(s => s.Name).Distinct().ToList());
/// The scheme name and one of its previous names (RedbScheme.RenamedFrom) are both stored.
internal static RedbRenameConflictException SchemeBothStored(Type type, string schemeName, string previousName,
long id, long previousId)
=> new($"Type '{type.FullName ?? type.Name}' declares scheme '{schemeName}' renamed from '{previousName}', but " +
$"the database stores both '{schemeName}' (scheme {id}) and '{previousName}' (scheme {previousId}). " +
"Renaming would leave the objects of one of them behind. Move the objects to one scheme and delete the " +
"other by hand, then start again.",
schemeName, schemeName, [previousName]);
/// More than one stored scheme matches the previous names of one class.
internal static RedbRenameConflictException SchemeSeveralStored(Type type, string schemeName,
IReadOnlyList<(string Name, long Id)> stored)
=> new($"Type '{type.FullName ?? type.Name}' declares scheme '{schemeName}', and more than one of its previous " +
"names is stored: " + string.Join(", ", stored.Select(s => $"'{s.Name}' (scheme {s.Id})")) +
". Keep one scheme and delete the others by hand, then start again.",
schemeName, schemeName, stored.Select(s => s.Name).ToList());
///
/// The class declares a scheme name that the database records as renamed, and no class of this application declares
/// the scheme under its current name: the class is older than the rename.
///
internal static RedbRenameConflictException SchemeRenamedAway(Type type, string schemeName, string currentName, long id)
=> new($"Type '{type.FullName ?? type.Name}' declares scheme '{schemeName}', but the database records that " +
$"'{schemeName}' was renamed to '{currentName}' (scheme {id}). This application runs a class older than " +
$"the rename. Update it to the class of '{currentName}'; nothing was changed. If a class of this " +
$"application does declare '{currentName}' in a module not loaded yet, load that module before this one.",
currentName, schemeName, [currentName]);
///
/// The database records a rename history for the property, and the first
/// of the property is not the first name of that history, or the property has none. The first name orders the
/// property in the object hash, so the class would compute the hashes in another order than they were stored.
///
internal static RedbRenameConflictException FirstNameMismatch(string schemeName, string propertyPath, long id,
IReadOnlyList history, string? declaredFirst)
=> new($"Scheme '{schemeName}': the database records that property '{propertyPath}' (structure {id}) was " +
$"renamed from {string.Join(", ", history.Select(n => $"'{n}'"))}, so its first [RedbRename] must be " +
$"[RedbRename(\"{history[0]}\")]; " +
(declaredFirst == null
? "the property declares none. "
: $"the property declares [RedbRename(\"{declaredFirst}\")] first. ") +
"[RedbRename] stays on a renamed property for good: its first name orders the property in the object " +
"hash. Restore the attributes, the first name first; nothing was changed.",
schemeName, propertyPath, history.ToList());
///
/// The class declares a property under a name that the database records as renamed: the class is older than the
/// rename, and adding the property again would split the values and, under the strict sync, delete the renamed one.
///
internal static RedbRenameConflictException RenamedAway(string schemeName, string propertyPath, string currentName,
long id)
=> new($"Scheme '{schemeName}': the class declares property '{propertyPath}', but the database records that " +
$"'{propertyPath}' was renamed to '{currentName}' (structure {id}). This application runs a class " +
$"older than the rename. Update it to the class with '{currentName}'; nothing was changed.",
schemeName, propertyPath, [currentName]);
}