use of org.apache.ignite.internal.processors.platform.PlatformExtendedException in project ignite by apache.
the class PlatformUtils method errorData.
/**
* Get error data.
*
* @param err Error.
* @return Error data.
*/
@SuppressWarnings("UnusedDeclaration")
public static byte[] errorData(Throwable err) {
if (err instanceof PlatformExtendedException) {
PlatformContext ctx = ((PlatformExtendedException) err).context();
try (PlatformMemory mem = ctx.memory().allocate()) {
// Write error data.
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
try {
PlatformUtils.writeErrorData(err, writer, ctx.kernalContext().log(PlatformContext.class));
} finally {
out.synchronize();
}
// Read error data into separate array.
PlatformInputStream in = mem.input();
in.synchronize();
int len = in.remaining();
assert len > 0;
byte[] arr = in.array();
byte[] res = new byte[len];
System.arraycopy(arr, 0, res, 0, len);
return res;
}
} else
return null;
}
use of org.apache.ignite.internal.processors.platform.PlatformExtendedException in project ignite by apache.
the class PlatformUtils method writeErrorData.
/**
* Write error data.
* @param err Error.
* @param writer Writer.
* @param log Optional logger.
*/
public static void writeErrorData(Throwable err, BinaryRawWriterEx writer, @Nullable IgniteLogger log) {
// Write additional data if needed.
if (err instanceof PlatformExtendedException) {
PlatformExtendedException err0 = (PlatformExtendedException) err;
// Data exists.
writer.writeBoolean(true);
int pos = writer.out().position();
try {
// Optimistically assume that we will be able to write it.
writer.writeBoolean(true);
err0.writeData(writer);
} catch (Exception e) {
if (log != null)
U.warn(log, "Failed to write interop exception data: " + e.getMessage(), e);
writer.out().position(pos);
// Error occurred.
writer.writeBoolean(false);
writer.writeString(e.getClass().getName());
String innerMsg;
try {
innerMsg = e.getMessage();
} catch (Exception ignored) {
innerMsg = "Exception message is not available.";
}
writer.writeString(innerMsg);
}
} else
writer.writeBoolean(false);
}
Aggregations