Ejemplo n.º 1
0
        public void RoundtripException()
        {
            var exception = new Google.Rpc.Status
            {
                Details = { new ErrorInfo {
                                Reason = "some reason"
                            } }
            }.ToException();

            var message = exception.GetDetail <ErrorInfo>();

            message.Should().NotBeNull();
            message !.Reason.Should().Be("some reason");
        }
Ejemplo n.º 2
0
        public void StatusToException()
        {
            var exception = new Google.Rpc.Status
            {
                Code    = (int)StatusCode.NotFound,
                Message = "some message"
            }.ToException();

            exception.Status.StatusCode.Should().Be(StatusCode.NotFound);
            exception.Status.Detail.Should().Be("some message");

            var richStatus = exception.GetRichStatus();

            richStatus.Should().NotBeNull();
            richStatus !.Code.Should().Be((int)StatusCode.NotFound);
            richStatus !.Message.Should().Be("some message");
        }
        public void ValidTrailer_GetRpcStatus()
        {
            var status = new Status
            {
                Code    = 123,
                Message = "This is a message",
            };

            var metadata = new Metadata();

            metadata.Add(RpcExceptionExtensions.StatusDetailsTrailerName, status.ToByteArray());
            RpcException ex = new RpcException(s_status, metadata);

            Assert.Equal(status, ex.GetRpcStatus());
            // We don't have any details
            Assert.Null(ex.GetBadRequest());
            Assert.Null(ex.GetErrorInfo());
            Assert.Null(ex.GetStatusDetail <DebugInfo>());
        }
        public void ValidTrailer_ArbitraryMessages()
        {
            var debugInfo = new DebugInfo
            {
                Detail = "This is some debugging information"
            };
            var requestInfo = new RequestInfo
            {
                RequestId = "request-id"
            };
            var badRequest = new BadRequest
            {
                FieldViolations = { new BadRequest.Types.FieldViolation {
                                        Description = "Negative", Field = "speed"
                                    } }
            };
            var status = new Status
            {
                Code    = 123,
                Message = "This is a message",
                Details =
                {
                    Any.Pack(debugInfo),
                    Any.Pack(requestInfo),
                    Any.Pack(badRequest)
                }
            };

            var metadata = new Metadata();

            metadata.Add("key-1", "value1");
            metadata.Add(RpcExceptionExtensions.StatusDetailsTrailerName, status.ToByteArray());
            metadata.Add("other-info-bin", new byte[] { 1, 2, 3 });
            metadata.Add("key-2", "value2");
            RpcException ex = new RpcException(s_status, metadata);

            Assert.Equal(badRequest, ex.GetBadRequest());
            Assert.Null(ex.GetErrorInfo());
            Assert.Equal(debugInfo, ex.GetStatusDetail <DebugInfo>());
            Assert.Equal(requestInfo, ex.GetStatusDetail <RequestInfo>());
            Assert.Equal(badRequest, ex.GetStatusDetail <BadRequest>());
        }
        public void GetStatusDetail_BadlyPackedMessage()
        {
            var debugInfo = new DebugInfo {
                Detail = "Debug information"
            };
            var any = Any.Pack(debugInfo);

            any.Value = ByteString.CopyFromUtf8("This isn't valid data!");

            var status = new Status {
                Details = { any }
            };
            var metadata = new Metadata();

            metadata.Add(RpcExceptionExtensions.StatusDetailsTrailerName, status.ToByteArray());
            RpcException ex = new RpcException(s_status, metadata);

            Assert.Equal(status, ex.GetRpcStatus());
            Assert.Null(ex.GetStatusDetail <DebugInfo>());
        }
        public void GetErrorInfo_Present()
        {
            var errorInfo = new ErrorInfo
            {
                Domain = "googleapis.com",
                Reason = "broken"
            };
            var status = new Status
            {
                Code    = 123,
                Message = "This is a message",
                Details =
                {
                    Any.Pack(errorInfo),
                }
            };
            var metadata = new Metadata();

            metadata.Add(RpcExceptionExtensions.StatusDetailsTrailerName, status.ToByteArray());

            RpcException ex = new RpcException(s_status, metadata);

            Assert.Equal(errorInfo, ex.GetErrorInfo());
        }
 /// <summary>
 /// Creates a new instance of <see cref="SpannerException"/>.
 /// </summary>
 /// <param name="status">The value from which to create the exception from.</param>
 protected internal SpannerException(Status status)
     : this(s_apiCodeToErrorCodes.TryGetValue(status?.Code ?? -1, out ErrorCode errorCode) ? errorCode : ErrorCode.Unknown,
            status?.Message ?? "An unknown Rpc error occurred.")
 {
 }