Fix batch 3: R-N wire refusal codes, R-P one authorizer id, R-T removal/cites gaps
R-N: cultnet.error.v0 gains additive code/details fields (contracts/cultnet). CultNetErrorMessage grows ForSelectionInvalid/ForCursor/ForReferenceOutsideTarget factories; both C# servers (CultNetDatabaseServer for snapshot+live, CultNetDatabaseSubscriptionServer) use them at every existing catch site, plus two sites that previously let the exception escape uncaught instead of reaching the peer (CultNetDatabaseServer's v1 subscribe snapshot branch, CultNetDatabaseSubscriptionServer's Subscribe around CreateProjectedSnapshot). CultNetSelectionCursorException now carries AsOf/Current for cursor_stale. R-P: CultNetDatabaseSubscriptionServer.CreateMatchedRecord (the live fast path) authorized against descriptor.SchemaId; the snapshot path (CreateProjectedSnapshot) already authorized against the wire id. Both now call the same CultNetDocumentRegistry.WireSchemaId (made internal, was private) so one id reaches the authorizer on the snapshot, live and reconcile paths alike. R-T(a): CultNetSelectionEvaluator.MatchesSchemaKeysFields no longer reads a Removed change's (always-null) document against Fields - it matches on keys/schemas alone and treats a field predicate as unknown instead of throwing TryGetIndexValue(null). R-T(b): EnsureWithinDeclaredTarget no longer skips the out-of-target check when TargetType is null; it checks against every registered leaf (unconstrained is a real, checked target set, not a bypass). CultCache's ResolveReferenceTarget also now infers the target from a many reference's CultRecordRef<T> element when no explicit [CultReference(typeof(...))] is declared, which was the one remaining source of a null TargetType reaching that check on a real, testable path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
c606eb38f2
commit
66b5e60b43
7 changed files with 191 additions and 18 deletions
|
|
@ -509,6 +509,70 @@ namespace GameCult.Networking
|
|||
/// Gets or sets optional shard routing details for authority failures.
|
||||
/// </summary>
|
||||
[Key("routingHint")] public CultNetShardRoutingHint? RoutingHint { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the machine-readable refusal code (R-N), e.g. <c>selection_invalid</c>,
|
||||
/// <c>cursor_stale</c>, <c>cursor_invalid</c>, <c>reference_outside_target</c>. Additive to
|
||||
/// <c>cultnet.error.v0</c>; a v0 peer that does not know this field ignores it.
|
||||
/// </summary>
|
||||
[Key("code")] public string? Code { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the code-specific structured detail (R-N). Additive to <c>cultnet.error.v0</c>.
|
||||
/// </summary>
|
||||
[Key("details")] public CultNetErrorDetails? Details { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Builds the wire error for a door refusal (R-N): code <c>selection_invalid</c>, details
|
||||
/// <c>{ field, value }</c>.
|
||||
/// </summary>
|
||||
public static CultNetErrorMessage ForSelectionInvalid(CultNetSelectionInvalidException ex) =>
|
||||
new CultNetErrorMessage
|
||||
{
|
||||
Error = $"selection_invalid: {ex.Message}",
|
||||
Code = "selection_invalid",
|
||||
Details = new CultNetErrorDetails { Field = ex.Field, Value = ex.Value }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Builds the wire error for a cursor refusal (R-N): code <c>cursor_stale</c> with details
|
||||
/// <c>{ asOf, current }</c>, or code <c>cursor_invalid</c> with no details.
|
||||
/// </summary>
|
||||
public static CultNetErrorMessage ForCursor(CultNetSelectionCursorException ex) =>
|
||||
new CultNetErrorMessage
|
||||
{
|
||||
Error = $"{ex.Code}: {ex.Message}",
|
||||
Code = ex.Code,
|
||||
Details = ex.Code == "cursor_stale"
|
||||
? new CultNetErrorDetails { AsOf = ex.AsOf, Current = ex.Current }
|
||||
: null
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Builds the wire error for an out-of-target reference refusal (R-N): code
|
||||
/// <c>reference_outside_target</c>, no details.
|
||||
/// </summary>
|
||||
public static CultNetErrorMessage ForReferenceOutsideTarget(CultNetSelectionReferenceOutsideTargetException ex) =>
|
||||
new CultNetErrorMessage
|
||||
{
|
||||
Error = $"reference_outside_target: {ex.Message}",
|
||||
Code = "reference_outside_target"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code-specific structured detail carried on <see cref="CultNetErrorMessage"/> (R-N). Fields are
|
||||
/// populated only for the code that defines them; every field is otherwise omitted (nil on the wire).
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class CultNetErrorDetails
|
||||
{
|
||||
/// <summary>The selection field that failed (<c>selection_invalid</c>).</summary>
|
||||
[Key("field")] public string? Field { get; set; }
|
||||
/// <summary>The offending value, when there is one string worth naming (<c>selection_invalid</c>).</summary>
|
||||
[Key("value")] public string? Value { get; set; }
|
||||
/// <summary>The cursor's own minted asOf (<c>cursor_stale</c>).</summary>
|
||||
[Key("asOf")] public ulong? AsOf { get; set; }
|
||||
/// <summary>The answering server's current asOf (<c>cursor_stale</c>).</summary>
|
||||
[Key("current")] public ulong? Current { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue