chore(historian): HistorianGateway Client/Contracts 1.1.0, typed error reason (#900)
v2-ci / unit-tests (push) Has been cancelled

Bump ZB.MOM.WW.HistorianGateway.Client + Contracts 1.0.0 -> 1.1.0 (historiangw#135,
release 6365f34). GatewayErrorReasons now reads Client 1.1.0's typed
HistorianGatewayException.StatusCode / ErrorReason / ErrorDomain (constants from
HistorianGatewayErrorReasons) instead of parsing grpc-status-details-bin itself; the
direct Grpc.StatusProto pin and reference are dropped (the client brings it). The
published client maps every RpcException to a HistorianGatewayException, so the
trailer fallback is not needed. Behaviour unchanged: FailedPrecondition +
AGGREGATE_NOT_SUPPORTED_FOR_TAG (domain historian_gateway.v1) ->
BadAggregateNotSupported, everything else keeps its handling.

Adds GatewayErrorReasonsTests (typed-property-only exceptions, so they fail against
the old trailer implementation); wire tests and docs/Historian.md updated.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-13 07:17:10 -05:00
parent 97d513f7dc
commit 76e73e7dbf
7 changed files with 98 additions and 61 deletions
@@ -22,8 +22,9 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests;
/// <c>FailedPrecondition</c>, detail <c>HistorianAggregateNotSupportedException</c>, and a <c>google.rpc.Status</c> holding a
/// <c>google.rpc.ErrorInfo</c> (reason <c>AGGREGATE_NOT_SUPPORTED_FOR_TAG</c>, domain <c>historian_gateway.v1</c>, metadata
/// <c>retrieval_mode</c> + <c>native_error_code</c>) in <c>grpc-status-details-bin</c> (shape copied from the gateway's
/// <c>HistorianRpcFaults.ToRpcException</c>). Read through the PUBLISHED Client 1.0.0 (via the production adapter), so this
/// also pins that 1.0.0 keeps the trailer on the exception it throws. Controls: every other shape keeps today's handling
/// <c>HistorianRpcFaults.ToRpcException</c>). Read through the PUBLISHED Client 1.1.0 (via the production adapter), so this
/// also pins that 1.1.0 surfaces the trailer as the typed <c>HistorianGatewayException.ErrorReason</c> /
/// <c>ErrorDomain</c> / <c>StatusCode</c> that <c>GatewayErrorReasons</c> reads. Controls: every other shape keeps today's handling
/// (rethrown, counted as a backend failure).
/// </summary>
public sealed class GatewayAggregateNotSupportedWireTests
@@ -0,0 +1,63 @@
using Grpc.Core;
using Shouldly;
using Xunit;
using ZB.MOM.WW.HistorianGateway.Client;
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests;
/// <summary>
/// lmxopcua#900 on Client 1.1.0: <see cref="GatewayErrorReasons"/> classifies by the client's typed
/// <see cref="HistorianGatewayException.StatusCode"/> / <see cref="HistorianGatewayException.ErrorReason"/> /
/// <see cref="HistorianGatewayException.ErrorDomain"/>. These exceptions carry the reason ONLY on the typed properties
/// (no inner <see cref="RpcException"/>, no trailer), so they pin that the typed accessor is what is read. The on-the-wire
/// path through the published client is <see cref="GatewayAggregateNotSupportedWireTests"/>.
/// </summary>
public sealed class GatewayErrorReasonsTests
{
private static HistorianGatewayException Gw(StatusCode? code, string? reason, string? domain) =>
new("x") { StatusCode = code, ErrorReason = reason, ErrorDomain = domain };
[Fact]
public void FailedPrecondition_with_the_gateways_aggregate_reason_is_the_refusal()
{
var ex = Gw(StatusCode.FailedPrecondition, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, HistorianGatewayErrorReasons.Domain);
GatewayErrorReasons.IsAggregateNotSupportedForTag(ex).ShouldBeTrue();
GatewayErrorReasons.ReasonOf(ex).ShouldBe("AGGREGATE_NOT_SUPPORTED_FOR_TAG");
}
[Fact]
public void The_refusal_is_found_when_wrapped()
{
var ex = new InvalidOperationException("outer",
Gw(StatusCode.FailedPrecondition, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, HistorianGatewayErrorReasons.Domain));
GatewayErrorReasons.IsAggregateNotSupportedForTag(ex).ShouldBeTrue();
}
public static TheoryData<StatusCode?, string?, string?> NotTheRefusal() => new()
{
{ StatusCode.Internal, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, HistorianGatewayErrorReasons.Domain },
{ null, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, HistorianGatewayErrorReasons.Domain },
{ StatusCode.FailedPrecondition, null, null },
{ StatusCode.FailedPrecondition, "LIVE_WRITES_DISABLED", HistorianGatewayErrorReasons.Domain },
{ StatusCode.FailedPrecondition, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, "example.com" },
{ StatusCode.FailedPrecondition, HistorianGatewayErrorReasons.AggregateNotSupportedForTag, null },
};
[Theory]
[MemberData(nameof(NotTheRefusal))]
public void Every_other_shape_is_not_the_refusal(StatusCode? code, string? reason, string? domain) =>
GatewayErrorReasons.IsAggregateNotSupportedForTag(Gw(code, reason, domain)).ShouldBeFalse();
[Fact]
public void A_foreign_domains_reason_is_no_reason() =>
GatewayErrorReasons.ReasonOf(Gw(StatusCode.FailedPrecondition, "AGGREGATE_NOT_SUPPORTED_FOR_TAG", "example.com")).ShouldBeNull();
[Fact]
public void A_non_gateway_exception_is_not_the_refusal()
{
GatewayErrorReasons.IsAggregateNotSupportedForTag(new IOException("x")).ShouldBeFalse();
GatewayErrorReasons.ReasonOf(new IOException("x")).ShouldBeNull();
}
}