diff --git a/xds/src/main/java/io/grpc/xds/XdsNameResolver.java b/xds/src/main/java/io/grpc/xds/XdsNameResolver.java index 01014027772..ed7b849f8be 100644 --- a/xds/src/main/java/io/grpc/xds/XdsNameResolver.java +++ b/xds/src/main/java/io/grpc/xds/XdsNameResolver.java @@ -722,7 +722,9 @@ public void run() { if (stopped || receivedConfig) { return; } - listener.onError(error); + listener.onError(Status.UNAVAILABLE.withCause(error.getCause()).withDescription( + String.format("Unable to load LDS %s. xDS server returned: %s: %s.", + ldsResourceName, error.getCode(), error.getDescription()))); } }); } @@ -920,7 +922,9 @@ public void run() { if (RouteDiscoveryState.this != routeDiscoveryState || receivedConfig) { return; } - listener.onError(error); + listener.onError(Status.UNAVAILABLE.withCause(error.getCause()).withDescription( + String.format("Unable to load RDS %s. xDS server returned: %s: %s.", + resourceName, error.getCode(), error.getDescription()))); } }); } diff --git a/xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java b/xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java index a17a043af5e..8cc78b7447c 100644 --- a/xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java +++ b/xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java @@ -431,7 +431,21 @@ public void resolving_encounterErrorLdsWatcherOnly() { verify(mockListener).onError(errorCaptor.capture()); Status error = errorCaptor.getValue(); assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE); - assertThat(error.getDescription()).isEqualTo("server unreachable"); + assertThat(error.getDescription()).isEqualTo("Unable to load LDS " + AUTHORITY + + ". xDS server returned: UNAVAILABLE: server unreachable."); + } + + @Test + public void resolving_translateErrorLds() { + resolver.start(mockListener); + FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient(); + xdsClient.deliverError(Status.NOT_FOUND.withDescription("server unreachable")); + verify(mockListener).onError(errorCaptor.capture()); + Status error = errorCaptor.getValue(); + assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE); + assertThat(error.getDescription()).isEqualTo("Unable to load LDS " + AUTHORITY + + ". xDS server returned: NOT_FOUND: server unreachable."); + assertThat(error.getCause()).isNull(); } @Test @@ -441,10 +455,14 @@ public void resolving_encounterErrorLdsAndRdsWatchers() { xdsClient.deliverLdsUpdateForRdsName(RDS_RESOURCE_NAME); xdsClient.deliverError(Status.UNAVAILABLE.withDescription("server unreachable")); verify(mockListener, times(2)).onError(errorCaptor.capture()); - for (Status error : errorCaptor.getAllValues()) { - assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE); - assertThat(error.getDescription()).isEqualTo("server unreachable"); - } + Status error = errorCaptor.getAllValues().get(0); + assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE); + assertThat(error.getDescription()).isEqualTo("Unable to load LDS " + AUTHORITY + + ". xDS server returned: UNAVAILABLE: server unreachable."); + error = errorCaptor.getAllValues().get(1); + assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE); + assertThat(error.getDescription()).isEqualTo("Unable to load RDS " + RDS_RESOURCE_NAME + + ". xDS server returned: UNAVAILABLE: server unreachable."); } @Test