Path: redb/redb.Core/Exceptions/RedbObjectReferencedException.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/RedbObjectReferencedException.cs
----
namespace redb.Core.Exceptions;
///
/// Objects of a trash container are still referenced by live objects - a RedbObject<T>
/// reference in their Props points at them - so they cannot be physically deleted without breaking
/// those references.
///
/// redb never repairs this on its own: nulling the references would hide the caller's mistake inside
/// other objects' data. The purge removes everything else of the container, marks the container
/// failed (the background worker no longer retries it) and names both sides here, so the
/// references can be removed or re-pointed deliberately. Purging the container again afterwards
/// finishes it.
///
///
public class RedbObjectReferencedException : Exception
{
/// The trash container that could not be purged completely.
public long TrashId { get; }
/// Objects still left in the container.
public long RemainingCount { get; }
/// Objects that live objects still reference (the first pairs found, at most 100).
public IReadOnlyList ReferencedObjectIds { get; }
/// Live objects holding those references.
public IReadOnlyList ReferencingObjectIds { get; }
public RedbObjectReferencedException(
long trashId,
long remainingCount,
IReadOnlyList referencedObjectIds,
IReadOnlyList referencingObjectIds)
: base(BuildMessage(trashId, remainingCount, referencedObjectIds, referencingObjectIds))
{
TrashId = trashId;
RemainingCount = remainingCount;
ReferencedObjectIds = referencedObjectIds;
ReferencingObjectIds = referencingObjectIds;
}
private static string BuildMessage(long trashId, long remaining, IReadOnlyList referenced, IReadOnlyList referencing) =>
$"Trash container {trashId} cannot be purged completely: {remaining} object(s) are still referenced by " +
$"live objects (referenced: {Ids(referenced)}; referencing: {Ids(referencing)}). Everything else was purged. " +
"The container is marked 'failed' and is no longer retried automatically; remove or re-point those " +
"references, then purge the container again.";
private static string Ids(IReadOnlyList ids) =>
ids.Count <= 20
? string.Join(", ", ids)
: string.Join(", ", ids.Take(20)) + $" and {ids.Count - 20} more";
}