org.hyperledger.fabric.client.GrpcStackTracePrinter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fabric-gateway Show documentation
Show all versions of fabric-gateway Show documentation
Hyperledger Fabric Gateway client API for Java
The newest version!
/*
* Copyright 2021 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.fabric.client;
import java.io.CharArrayWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.function.Consumer;
import org.hyperledger.fabric.protos.gateway.ErrorDetail;
class GrpcStackTracePrinter {
private final Consumer printStackTraceFn;
private final GrpcStatus grpcStatus;
public GrpcStackTracePrinter(final Consumer printStackTraceFn, final GrpcStatus grpcStatus) {
this.printStackTraceFn = printStackTraceFn;
this.grpcStatus = grpcStatus;
}
public void printStackTrace(final PrintStream out) {
PrintWriter writer = new PrintWriter(out);
printStackTrace(writer);
writer.flush();
}
public void printStackTrace(final PrintWriter out) {
CharArrayWriter message = new CharArrayWriter();
try (PrintWriter printer = new PrintWriter(message)) {
printStackTraceFn.accept(printer);
}
List details = grpcStatus.getDetails();
if (!details.isEmpty()) {
message.append("Error details:\n");
for (ErrorDetail detail : details) {
message.append(" address: ")
.append(detail.getAddress())
.append("; mspId: ")
.append(detail.getMspId())
.append("; message: ")
.append(detail.getMessage())
.append('\n');
}
}
out.print(message);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy