/** * This constructor is a convencience function to allow simpler instantiation of a result that contains an error. * It does nothing but proxy the {@link #Result(Error)} function with a new instance of {@link Error}. * * @param code The numerical code of the error. * @param message The description of the error. */ public Result(int code, String message) { this(new Error(code, message)); }
/** * <p>Returns whether or not this reply contains any fatal errors.</p> * * @return True if it contains fatal errors. */ public boolean hasFatalErrors() { for (Error error : errors) { if (error.getCode() >= ErrorCode.FATAL_ERROR) { return true; } } return false; }
private static String getErrorMessage(Error r) { return DocumentProtocol.getErrorName(r.getCode()) + ": " + r.getMessage(); }
@Override public void run() { Reply reply = decode(envelope.reply.getProtocol(), payload, Reply.class); reply.setRetryDelay(envelope.reply.getRetryDelay()); reply.getTrace().getRoot().addChild(TraceNode.decode(envelope.reply.getTrace().getRoot().encode())); for (int i = 0, len = envelope.reply.getNumErrors(); i < len; ++i) { Error error = envelope.reply.getError(i); reply.addError(new Error(error.getCode(), error.getMessage(), error.getService() != null ? error.getService() : envelope.sender.hostId)); } owner.deliverReply(reply, envelope.parent.recipient); } });
@Override protected void createResponse(Values ret, Reply reply, Version version, byte [] payload) { int[] eCodes = new int[reply.getNumErrors()]; String[] eMessages = new String[reply.getNumErrors()]; String[] eServices = new String[reply.getNumErrors()]; for (int i = 0; i < reply.getNumErrors(); ++i) { Error error = reply.getError(i); eCodes[i] = error.getCode(); eMessages[i] = error.getMessage(); eServices[i] = error.getService() != null ? error.getService() : ""; } ret.add(new StringValue(version.toString())); ret.add(new DoubleValue(reply.getRetryDelay())); ret.add(new Int32Array(eCodes)); ret.add(new StringArray(eMessages)); ret.add(new StringArray(eServices)); ret.add(new StringValue(reply.getProtocol())); ret.add(new DataValue(payload)); ret.add(new StringValue(reply.getTrace().getRoot() != null ? reply.getTrace().getRoot().encode() : "")); }
updateOpsPerSec(); log(LogLevel.DEBUG, "Sent message successfully, document id: ", msg.get().getOperationId()); } else if (!result.getError().isFatal()) { repliesFromOldMessages.add(createOperationStatus(msg.get().getOperationId(), result.getError().getMessage(), ErrorCode.TRANSIENT_ERROR, false, msg.get().getMessage())); continue; boolean isConditionNotMet = result.getError().getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED; repliesFromOldMessages.add(createOperationStatus(msg.get().getOperationId(), result.getError().getMessage(), ErrorCode.ERROR, isConditionNotMet, msg.get().getMessage())); continue;
private boolean sendMessage(final MbusRequest request) { Error error; final Long millis = request.timeRemaining(TimeUnit.MILLISECONDS); if (millis != null && millis <= 0) { error = new Error(ErrorCode.TIMEOUT, request.getTimeout(TimeUnit.MILLISECONDS) + " millis"); } else if (request.isCancelled()) { error = new Error(ErrorCode.APP_FATAL_ERROR, "request cancelled"); } else { try { error = session.sendMessage(request.getMessage()).getError(); } catch (final Exception e) { error = new Error(ErrorCode.FATAL_ERROR, e.toString()); } } if (error == null) { return true; } if (error.isFatal()) { final Reply reply = new EmptyReply(); reply.swapState(request.getMessage()); reply.addError(error); reply.popHandler().handleReply(reply); return true; } return false; }
for (int i = 0; i < node.reply.getNumErrors(); ++i) { Error error = node.reply.getError(i); int errorCode = error.getCode(); RoutingNode it = node; while (it != null) { errors.append("\n"); errors.append(error.toString()); shouldRetry = resender != null && resender.canRetry(errorCode); if (!shouldRetry) {
@Override public ContentChannel handleResponse(Response response) { Reply reply; if (response instanceof MbusResponse) { reply = ((MbusResponse)response).getReply(); } else { reply = new EmptyReply(); reply.swapState(msg); } Error err = StatusCodes.toMbusError(response.getStatus()); if (err != null) { if (err.isFatal()) { if (!reply.hasFatalErrors()) { reply.addError(err); } } else { if (!reply.hasErrors()) { reply.addError(err); } } } if (reply.getTrace().shouldTrace(6)) { reply.getTrace().trace(6, "Sending reply from MbusServer."); } session.sendReply(reply); return null; } }
/** * <p>Add an error to this reply. This method will also trace the error as long as there is any tracing * enabled.</p> * * @param error The error object to add. */ public void addError(Error error) { errors.add(error); getTrace().trace(TraceLevel.ERROR, error.toString()); }
Cursor e = array.addObject(); Error mbusE = reply.getError(i); e.setLong(CODE_F, mbusE.getCode()); e.setString(MSG_F, mbusE.getMessage()); if (mbusE.getService() != null) { e.setString(SERVICE_F, mbusE.getService());
public static Error toMbusError(final int statusCode) { if (statusCode < 300) { return null; } else if (statusCode < 400) { return new Error(ErrorCode.APP_TRANSIENT_ERROR, statusCode + " Redirection"); } else if (statusCode < 500) { return new Error(ErrorCode.APP_FATAL_ERROR, statusCode + " Client Error"); } else if (statusCode < 600) { return new Error(ErrorCode.APP_FATAL_ERROR, statusCode + " Server Error"); } else { return new Error(ErrorCode.APP_FATAL_ERROR, statusCode + " Unknown Error"); } } }
/** * Retrieves a set of integer error codes */ public Set<Integer> getErrorCodes() { Set<Integer> errorCodes = new HashSet<>(); for (Error error : errors) { errorCodes.add(error.getCode()); } return errorCodes; }
private static Result toResult(long reqId, com.yahoo.messagebus.Result mbusResult) { if (mbusResult.isAccepted()) { return new Result(reqId); } return new Result( messageBusErrorToResultType(mbusResult.getError().getCode()), new Error(mbusResult.getError().getMessage() + " (" + mbusResult.getError().getCode() + ")")); }
/** * This is a convenience method to call {@link #setError(Error)}. * * @param code The code of the error to set. * @param msg The message of the error to set. */ public void setError(int code, String msg) { setError(new Error(code, msg)); }
public static int fromMbusError(final Error error) { final int errorCode = error.getCode(); if (errorCode < ErrorCode.TRANSIENT_ERROR) { return Response.Status.OK;
@Override public void handleReply(Reply reply) { Object o = reply.getContext(); if (!(o instanceof ReplyContext)) { return; } ReplyContext context = (ReplyContext) o; final double latencyInSeconds = (System.currentTimeMillis() - context.creationTime) / 1000.0d; metric.set(MetricNames.LATENCY, latencyInSeconds, null); if (reply.hasErrors()) { Set<Integer> errorCodes = reply.getErrorCodes(); metricsHelper.reportFailure(DocumentOperationType.fromMessage(reply.getMessage()), DocumentOperationStatus.fromMessageBusErrorCodes(errorCodes)); metric.add(MetricNames.FAILED, 1, null); enqueue(context, reply.getError(0).getMessage(), ErrorCode.ERROR, reply.getError(0).getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED, reply.getTrace()); } else { metricsHelper.reportSuccessful(DocumentOperationType.fromMessage(reply.getMessage()), latencyInSeconds); metric.add(MetricNames.SUCCEEDED, 1, null); enqueue(context, "Document processed.", ErrorCode.OK, false, reply.getTrace()); } }
/** * This is a convenience method to call {@link #addError(Error)}. * * @param code The code of the error to add. * @param msg The message of the error to add. */ public void addError(int code, String msg) { addError(new Error(code, msg)); }
private static boolean isErrorOfType(Reply reply, int errorCode) { return reply.getError(0).getCode() == errorCode; }