Path: redb/redb.Core/Exceptions/RedbSchemeNameTakenException.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/RedbSchemeNameTakenException.cs
----
namespace redb.Core.Exceptions;
///
/// Thrown when a type wants to rename its scheme to an explicit name that another scheme in the
/// database already occupies. Raised instead of letting the UNIQUE(_name) violation surface as a
/// provider-specific error code (23505 / 2627 / SQLITE_CONSTRAINT_UNIQUE), and the database is left
/// untouched.
///
public class RedbSchemeNameTakenException : Exception
{
/// The type that asked for the name.
public Type DeclaringType { get; }
/// The contested scheme name.
public string SchemeName { get; }
/// Id of the scheme already holding the name.
public long OccupiedBySchemeId { get; }
public RedbSchemeNameTakenException(Type declaringType, string schemeName, long occupiedBySchemeId)
: base($"Type '{declaringType.FullName ?? declaringType.Name}' declares " +
$"[RedbScheme(Name = \"{schemeName}\")], but scheme id={occupiedBySchemeId} already uses that name. " +
"Scheme names are unique — pick another name, or remove the stale scheme first.")
{
DeclaringType = declaringType;
SchemeName = schemeName;
OccupiedBySchemeId = occupiedBySchemeId;
}
///
/// The type resolves to two different schemes at once: one already carries the explicit name, and
/// another still sits under a previous name. That is the split-brain of a rename -
/// typically an older binary re-created the scheme under its old name after a newer one had renamed it, and
/// objects are now being written to both.
///
public RedbSchemeNameTakenException(
Type declaringType, string schemeName, long occupiedBySchemeId, string previousName, long previousSchemeId)
: base($"Type '{declaringType.FullName ?? declaringType.Name}' maps to two schemes at once: " +
$"id={occupiedBySchemeId} named '{schemeName}' and id={previousSchemeId} named '{previousName}'. " +
"The rename to the explicit name has already happened, yet the old scheme was re-created — " +
"most likely by an application version that predates the explicit name. Objects may be split " +
"across both schemes; merge them and remove the stale one before continuing.")
{
DeclaringType = declaringType;
SchemeName = schemeName;
OccupiedBySchemeId = occupiedBySchemeId;
}
}