private static BError generateError(Strand strand, boolean attachCallStack, BErrorType type, String reason, BMap<String, BValue> details) { BMap<String, BValue> detailMap = Optional.ofNullable(details).orElse(new BMap<>(BTypes.typeMap)); BError error = new BError(type, Optional.ofNullable(reason).orElse(""), detailMap); StructureTypeInfo typeInfo = getStructureTypeInfo(strand.programFile); if (attachCallStack) { attachStack(error, typeInfo, strand); } return error; }
protected void printError(BError error) { BLangVMUtils.log(error.stringValue()); }
private static void handleErrorBuiltinMethods(int opcode, int[] operands, StackFrame sf) { int i = operands[0]; int j = operands[1]; BError error = (BError) sf.refRegs[i]; switch (opcode) { case InstructionCodes.REASON: sf.stringRegs[j] = error.getReason(); break; case InstructionCodes.DETAIL: sf.refRegs[j] = error.getDetails(); break; } }
private static String getErrorMessage(BError error) { String errorMsg = error.reason; BMap<String, BValue> errorDetails = (BMap<String, BValue>) error.getDetails(); if (!errorDetails.isEmpty()) { errorMsg = errorMsg.concat(COLON + errorDetails.get(HTTP_ERROR_MESSAGE)); } return errorMsg; }
@Override public void execute(Context context) { final BError errorStruct = (BError) context.getRefArgument(0); BValueArray errorStack = new BValueArray(errorStruct.getType()); for (int i = 0; i < errorStruct.callStack.size(); i++) { errorStack.add(i, errorStruct.callStack.get(i)); } context.setReturnValues(errorStack); }
void notifyErrorReply(Context context, String errorMessage) { BErrorType errType = BTypes.typeError; String reason = "{ballerina/grpc}" + INTERNAL.name(); BMap<String, BValue> refData = new BMap<>(errType.detailsType); refData.put("message", new BString(errorMessage)); context.setReturnValues(new BError(BTypes.typeError, reason, refData)); } }
public void execute(Context ctx) { logMessage(ctx, BLogLevel.ERROR, (pkg, message) -> { BError err = (BError) ctx.getNullableRefArgument(1); String errorMsg = (err == null) ? "" : " : " + err.stringValue(); getLogger(pkg).error(message + errorMsg); }); } }
private static BError getError(WebSocketOpenConnectionInfo connectionInfo, Throwable throwable) { String errMsg; if (isUnexpectedError(throwable)) { errMsg = "Unexpected internal error. Please check internal-log for more details!"; } else { errMsg = throwable.getMessage(); } Context context = connectionInfo.getContext(); if (context != null) { return HttpUtil.getError(context, errMsg); } else { ProgramFile programFile = connectionInfo.getService().getServiceInfo().getPackageInfo().getProgramFile(); BMap<String, BValue> httpErrorRecord = BLangConnectorSPIUtil.createBStruct( programFile, HttpConstants.PROTOCOL_PACKAGE_HTTP, HttpConstants.HTTP_ERROR_RECORD); httpErrorRecord.put(HttpConstants.HTTP_ERROR_MESSAGE, new BString(errMsg)); return new BError(BTypes.typeError, errMsg, httpErrorRecord); } }
/** * Handles failures in GRPC callable unit callback. * * @param streamObserver observer used the send the error back * @param error error message struct */ static void handleFailure(StreamObserver streamObserver, BError error) { String errorMsg = error.stringValue(); ErrorHandlerUtils.printError("error: " + BLangVMErrors.getPrintableStackTrace(error)); if (streamObserver != null) { streamObserver.onError(new Message(new StatusRuntimeException(Status.fromCodeValue(Status .Code.INTERNAL.value()).withDescription(errorMsg)))); } }
return new BError(errorType, reason, refData);