Refine search
@Override public void onError(Throwable ex) { logger.warn("Received error from server: {}", ex.getMessage()); outboundStreamObserver = null; if (ex instanceof StatusRuntimeException && ((StatusRuntimeException) ex).getStatus().getCode().equals(Status.UNAVAILABLE.getCode())) { return; } resubscribe(); }
@Override public Object[] parse(InputStream stream) { try { BinaryDecoder in = DECODER_FACTORY.binaryDecoder(stream, null); Schema reqSchema = message.getRequest(); GenericRecord request = (GenericRecord) new SpecificDatumReader<>(reqSchema).read(null, in); Object[] args = new Object[reqSchema.getFields().size()]; int i = 0; for (Schema.Field field : reqSchema.getFields()) { args[i++] = request.get(field.name()); } return args; } catch (IOException e) { throw Status.INTERNAL.withCause(e). withDescription("Error deserializing avro request arguments").asRuntimeException(); } finally { AvroGrpcUtils.skipAndCloseQuietly(stream); } }
/** * Dispatches the current response chunk to the client. This is only called by the executor. At * any time, a given dispatch task should only be registered with the executor once. */ private synchronized void dispatchChunk() { if (cancelled) { return; } try { // Pop off the next chunk and send it to the client. Chunk chunk = chunks.remove(); if (chunk == completionChunk) { responseStream.onCompleted(); } else { responseStream.onNext(chunk.toResponse()); } } catch (Throwable e) { failure = e; if (Status.fromThrowable(e).getCode() == Status.CANCELLED.getCode()) { // Stream was cancelled by client, responseStream.onError() might be called already or // will be called soon by inbounding StreamObserver. chunks.clear(); } else { responseStream.onError(e); } } }
private void verifySize() { if (count > maxMessageSize) { throw Status.RESOURCE_EXHAUSTED.withDescription(String.format( "%s: Compressed frame exceeds maximum frame size: %d. Bytes read: %d. ", debugString, maxMessageSize, count)).asRuntimeException(); } } }
@Override public void onError(Throwable t) { Metadata metadata = Status.trailersFromThrowable(t); if (metadata == null) { metadata = new Metadata(); } if (t instanceof MotanBizException) { call.close(Status.INTERNAL.withDescription(t.getMessage()).withCause(t), metadata); } else { call.close(Status.UNAVAILABLE.withDescription(t.getMessage()).withCause(t), metadata); } }
@Override public void onNext(SaslMessage saslMessage) { try { SaslMessage response = mSaslHandshakeClientHandler.handleSaslMessage(saslMessage); if (response == null) { mRequestObserver.onCompleted(); } else { mRequestObserver.onNext(response); } } catch (SaslException e) { mAuthenticated.setException(e); mRequestObserver .onError(Status.fromCode(Status.Code.UNAUTHENTICATED).withCause(e).asException()); } }
/** * Close the call with {@link Status#UNAUTHENTICATED}. * * @param call The call to close. * @param aex The exception that was the cause. */ protected void closeCallUnauthenticated(final ServerCall<?, ?> call, final AuthenticationException aex) { call.close(Status.UNAUTHENTICATED.withCause(aex).withDescription(UNAUTHENTICATED_DESCRIPTION), new Metadata()); }
@Test public void error_withMessage() throws Exception { final StatusRuntimeException t = (StatusRuntimeException) catchThrowable( () -> blockingClient.errorWithMessage(REQUEST_MESSAGE)); assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED); assertThat(t.getStatus().getDescription()).isEqualTo("aborted call"); checkRequestLog((rpcReq, rpcRes, grpcStatus) -> { assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/ErrorWithMessage"); assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE); assertThat(grpcStatus).isNotNull(); assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED); assertThat(grpcStatus.getDescription()).isEqualTo("aborted call"); }); }
Metadata metadata = new Metadata(); metadata.put(STATUS_DETAILS_KEY, DebugInfo.newBuilder() .addAllStackEntries(Arrays.asList(frames)) .withDescription(t.getMessage()) .withCause(t) .asException(metadata);
/** Convert an entry's status from a protobuf to an {@link ApiException}. */ private ApiException createEntryError(com.google.rpc.Status protoStatus) { io.grpc.Status grpcStatus = io.grpc.Status.fromCodeValue(protoStatus.getCode()) .withDescription(protoStatus.getMessage()); StatusCode gaxStatusCode = GrpcStatusCode.of(grpcStatus.getCode()); return ApiExceptionFactory.createException( grpcStatus.asRuntimeException(), gaxStatusCode, retryableCodes.contains(gaxStatusCode.getCode())); }
@Override public void onCompleted() { if (cancelled) { throw Status.CANCELLED.withDescription("call already cancelled").asRuntimeException(); } else { call.close(Status.OK, new Metadata()); } }
@Override public void errorWithMessage(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) { responseObserver.onError(Status.ABORTED.withDescription("aborted call").asException()); }
switch (Status.fromThrowable(e).getCode()) { case ABORTED: alluxioStatus = alluxio.exception.status.Status.ABORTED; if (e.getTrailers() != null && e.getTrailers().containsKey(sInnerCauseKey)) { try { cause = (Throwable) SerializationUtils.deserialize(e.getTrailers().get(sInnerCauseKey)); } catch (Exception exc) { LOG.warn("Failed to deserialize the cause: {}", exc);
@Test public void resourceExhaustedWithBackoff() { Status status = Status.fromCodeValue(Status.Code.RESOURCE_EXHAUSTED.value()) .withDescription("Memory pushback"); Metadata trailers = new Metadata(); Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance()); RetryInfo retryInfo = RetryInfo.newBuilder() .setRetryDelay(Duration.newBuilder().setNanos(1000000).setSeconds(1L)) .build(); trailers.put(key, retryInfo); SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status, trailers)); assertThat(e.isRetryable()).isTrue(); assertThat(e.getRetryDelayInMillis()).isEqualTo(1001); }
.withDescription("Unknown: " + req.getResponseCompression()) .asRuntimeException()); return; .withDescription("compression not supported.") .withCause(e) .asRuntimeException()); return; obs.onError(Status.fromCodeValue(req.getResponseStatus().getCode()) .withDescription(req.getResponseStatus().getMessage()) .asRuntimeException()); return;
requestParamsHeader.put(requestParamsKey, "name=" + kmsKeyRingResourcePath); KeyManagementServiceBlockingStub stubForGetKeyRing = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader); stubForGetKeyRing.getKeyRing(getKeyRingRequest); } catch (StatusRuntimeException ex) { if (ex.getStatus().getCode() == Status.Code.NOT_FOUND) { .setKeyRingId(keyRingName) .build(); requestParamsHeader.put(requestParamsKey, "parent=" + keyRingParent); KeyManagementServiceBlockingStub stubForCreateKeyRing = MetadataUtils.attachHeaders(kmsStub, requestParamsHeader);
@Override public void customException(EchoRequest request, StreamObserver<EchoResponse> responseObserver) { try { throw new CustomException("Custom exception!"); } catch (Exception e) { responseObserver.onError(Status.INTERNAL .withDescription(e.getMessage()) .augmentDescription("customException()") .withCause(e) // This can be attached to the Status locally, but NOT transmitted to the client! .asRuntimeException()); } }
Metadata trailers = new Metadata(); trailers.put(sInnerCauseKey, SerializationUtils.serialize(cause)); } catch (Exception exc) { LOG.warn("Could not serialize the cause: {}. Failed with: {}", cause, exc); return Status.fromCode(code).asException(trailers);
assertThat(t).isInstanceOf(StatusRuntimeException.class); final StatusRuntimeException e = (StatusRuntimeException) t; assertThat(e.getStatus().getCode()).isEqualTo(Status.UNKNOWN.getCode()); assertThat(e.getStatus().getDescription()).isEqualTo(errorMessage); assertThat(Status.fromThrowable(captor.getValue()).getCode()).isEqualTo(Status.UNKNOWN.getCode()); assertThat(Status.fromThrowable(captor.getValue()).getDescription()).isEqualTo(errorMessage); verifyNoMoreInteractions(responseObserver); assertThat(rpcReq.params()).containsExactly(simpleRequest); assertThat(grpcStatus).isNotNull(); assertThat(grpcStatus.getCode()).isEqualTo(Code.UNKNOWN); assertThat(grpcStatus.getDescription()).isEqualTo(errorMessage); });