Search in sources :

Example 1 with PlatformExtendedException

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;
}
Also used : PlatformExtendedException(org.apache.ignite.internal.processors.platform.PlatformExtendedException) PlatformInputStream(org.apache.ignite.internal.processors.platform.memory.PlatformInputStream) PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 2 with PlatformExtendedException

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);
}
Also used : PlatformExtendedException(org.apache.ignite.internal.processors.platform.PlatformExtendedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) PlatformExtendedException(org.apache.ignite.internal.processors.platform.PlatformExtendedException) CacheException(javax.cache.CacheException) PlatformNativeException(org.apache.ignite.internal.processors.platform.PlatformNativeException)

Aggregations

PlatformExtendedException (org.apache.ignite.internal.processors.platform.PlatformExtendedException)2 CacheException (javax.cache.CacheException)1 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)1 PlatformContext (org.apache.ignite.internal.processors.platform.PlatformContext)1 PlatformNativeException (org.apache.ignite.internal.processors.platform.PlatformNativeException)1 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)1 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)1 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)1