Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log stack traces at warn or error level #1283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apitest/src/main/java/haveno/apitest/ApiTestMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void execute(String[] args) {

} catch (Throwable ex) {
err.println("Fault: An unexpected error occurred. " +
"Please file a report at https://haveno.exchange/issues");
"Please file a report at https://github.com/haveno-dex/haveno/issues");
ex.printStackTrace(err);
exit(EXIT_FAILURE);
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ configure(project(':p2p')) {
implementation "com.google.protobuf:protobuf-java:$protobufVersion"
implementation "org.fxmisc.easybind:easybind:$easybindVersion"
implementation "org.slf4j:slf4j-api:$slf4jVersion"
implementation "org.apache.commons:commons-lang3:$langVersion"
implementation("com.github.haveno-dex.netlayer:tor.external:$netlayerVersion") {
exclude(module: 'slf4j-api')
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/haveno/common/app/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void setup(String fileName) {
errorTriggeringPolicy.start();

ThresholdFilter thresholdFilter = new ThresholdFilter();
thresholdFilter.setLevel("ERROR");
thresholdFilter.setLevel("WARN");
thresholdFilter.start();

errorAppender.setRollingPolicy(errorRollingPolicy);
Expand Down
8 changes: 3 additions & 5 deletions common/src/main/java/haveno/common/file/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public static void rollingBackup(File dir, String fileName, int numMaxBackupFile

pruneBackup(backupFileDir, numMaxBackupFiles);
} catch (IOException e) {
log.error("Backup key failed: " + e.getMessage());
e.printStackTrace();
log.error("Backup key failed: {}\n", e.getMessage(), e);
}
}
}
Expand Down Expand Up @@ -97,7 +96,7 @@ public static void deleteRollingBackup(File dir, String fileName) {
try {
FileUtils.deleteDirectory(backupFileDir);
} catch (IOException e) {
e.printStackTrace();
log.error("Delete backup key failed: {}\n", e.getMessage(), e);
}
}

Expand Down Expand Up @@ -173,8 +172,7 @@ public static void deleteFileIfExists(File file, boolean ignoreLockedFiles) thro
}
}
} catch (Throwable t) {
log.error(t.toString());
t.printStackTrace();
log.error("Could not delete file, error={}\n", t.getMessage(), t);
throw new IOException(t);
}
}
Expand Down
9 changes: 2 additions & 7 deletions common/src/main/java/haveno/common/setup/CommonSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ public static void setupUncaughtExceptionHandler(UncaughtExceptionHandler uncaug
"The system tray is not supported on the current platform.".equals(throwable.getMessage())) {
log.warn(throwable.getMessage());
} else {
log.error("Uncaught Exception from thread " + Thread.currentThread().getName());
log.error("throwableMessage= " + throwable.getMessage());
log.error("throwableClass= " + throwable.getClass());
log.error("Stack trace:\n" + ExceptionUtils.getStackTrace(throwable));
throwable.printStackTrace();
log.error("Uncaught Exception from thread {}, error={}\n", Thread.currentThread().getName(), throwable.getMessage(), throwable);
UserThread.execute(() -> uncaughtExceptionHandler.handleUncaughtException(throwable, false));
}
};
Expand Down Expand Up @@ -113,8 +109,7 @@ protected static void maybePrintPathOfCodeSource() {
if (!pathOfCodeSource.endsWith("classes"))
log.info("Path to Haveno jar file: " + pathOfCodeSource);
} catch (URISyntaxException e) {
log.error(e.toString());
e.printStackTrace();
log.error(ExceptionUtils.getStackTrace(e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.commons.lang3.exception.ExceptionUtils;

@Slf4j
public class TaskRunner<T extends Model> {
private final Queue<Class<? extends Task<T>>> tasks = new LinkedBlockingQueue<>();
Expand Down Expand Up @@ -67,8 +69,8 @@ private void next() {
log.info("Run task: " + currentTask.getSimpleName());
currentTask.getDeclaredConstructor(TaskRunner.class, sharedModelClass).newInstance(this, sharedModel).run();
} catch (Throwable throwable) {
throwable.printStackTrace();
handleErrorMessage("Error at taskRunner: " + throwable.getMessage());
log.error(ExceptionUtils.getStackTrace(throwable));
handleErrorMessage("Error at taskRunner, error=" + throwable.getMessage());
}
} else {
resultHandler.handleResult();
Expand Down
3 changes: 1 addition & 2 deletions common/src/main/java/haveno/common/util/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,7 @@ public static void copyToClipboard(String content) {
clipboard.setContent(clipboardContent);
}
} catch (Throwable e) {
log.error("copyToClipboard failed " + e.getMessage());
e.printStackTrace();
log.error("copyToClipboard failed: {}\n", e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
import java.util.Date;
import java.util.List;
import java.util.Optional;

import org.apache.commons.lang3.exception.ExceptionUtils;

import lombok.extern.slf4j.Slf4j;


Expand Down Expand Up @@ -204,7 +207,7 @@ public void resolveDispute(String tradeId, DisputeResult.Winner winner, DisputeR
throw new IllegalStateException(errMessage, err);
});
} catch (Exception e) {
e.printStackTrace();
log.error(ExceptionUtils.getStackTrace(e));
throw new IllegalStateException(e.getMessage() == null ? ("Error resolving dispute for trade " + trade.getId()) : e.getMessage());
}
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/haveno/core/api/CoreTradesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import java.util.Optional;
import java.util.function.Consumer;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.bitcoinj.core.Coin;

@Singleton
Expand Down Expand Up @@ -161,7 +163,7 @@ void takeOffer(Offer offer,
errorMessageHandler
);
} catch (Exception e) {
e.printStackTrace();
log.error(ExceptionUtils.getStackTrace(e));
errorMessageHandler.handleErrorMessage(e.getMessage());
}
}
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/haveno/core/api/XmrConnectionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.exception.ExceptionUtils;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.LongProperty;
import javafx.beans.property.ObjectProperty;
Expand Down Expand Up @@ -464,7 +467,7 @@ public void onAccountOpened() {
log.info(getClass() + ".onAccountOpened() called");
initialize();
} catch (Exception e) {
e.printStackTrace();
log.error("Error initializing connection service after account opened, error={}\n", e.getMessage(), e);
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -622,8 +625,7 @@ private void maybeStartLocalNode() {
log.info("Starting local node");
xmrLocalNode.startMoneroNode();
} catch (Exception e) {
log.warn("Unable to start local monero node: " + e.getMessage());
e.printStackTrace();
log.error("Unable to start local monero node, error={}\n", e.getMessage(), e);
}
}
}
Expand Down Expand Up @@ -721,8 +723,8 @@ private void doPollDaemon() {

// log error message periodically
if (lastLogPollErrorTimestamp == null || System.currentTimeMillis() - lastLogPollErrorTimestamp > HavenoUtils.LOG_POLL_ERROR_PERIOD_MS) {
log.warn("Failed to fetch daemon info, trying to switch to best connection: " + e.getMessage());
if (DevEnv.isDevMode()) e.printStackTrace();
log.warn("Failed to fetch daemon info, trying to switch to best connection, error={}", e.getMessage());
if (DevEnv.isDevMode()) log.error(ExceptionUtils.getStackTrace(e));
lastLogPollErrorTimestamp = System.currentTimeMillis();
}

Expand Down
10 changes: 4 additions & 6 deletions core/src/main/java/haveno/core/app/HavenoExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public int execute(String[] args) {
System.exit(EXIT_FAILURE);
} catch (Throwable ex) {
System.err.println("fault: An unexpected error occurred. " +
"Please file a report at https://haveno.exchange/issues");
"Please file a report at https://github.com/haveno-dex/haveno/issues");
ex.printStackTrace(System.err);
System.exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -201,8 +201,7 @@ protected void onApplicationLaunched() {
startApplication();
}
} catch (InterruptedException | ExecutionException e) {
log.error("An error occurred: {}", e.getMessage());
e.printStackTrace();
log.error("An error occurred: {}\n", e.getMessage(), e);
}
});
}
Expand Down Expand Up @@ -362,7 +361,7 @@ public void gracefulShutDown(ResultHandler onShutdown, boolean systemExit) {
try {
ThreadUtils.awaitTasks(tasks, tasks.size(), 90000l); // run in parallel with timeout
} catch (Exception e) {
e.printStackTrace();
log.error("Failed to notify all services to prepare for shutdown: {}\n", e.getMessage(), e);
}

injector.getInstance(TradeManager.class).shutDown();
Expand Down Expand Up @@ -397,8 +396,7 @@ public void gracefulShutDown(ResultHandler onShutdown, boolean systemExit) {
});
});
} catch (Throwable t) {
log.error("App shutdown failed with exception {}", t.toString());
t.printStackTrace();
log.error("App shutdown failed with exception: {}\n", t.getMessage(), t);
completeShutdown(resultHandler, EXIT_FAILURE, systemExit);
}
}
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/haveno/core/app/HavenoSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ private void maybeInstallDependencies() {
moneroWalletRpcFile.setExecutable(true);
}
} catch (Exception e) {
e.printStackTrace();
log.warn("Failed to install Monero binaries: " + e.toString());
log.warn("Failed to install Monero binaries: {}\n", e.getMessage(), e);
}
}

Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/haveno/core/app/TorSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import java.io.IOException;
import java.nio.file.Paths;
import javax.annotation.Nullable;

import org.apache.commons.lang3.exception.ExceptionUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand All @@ -48,8 +51,7 @@ public void cleanupTorFiles(@Nullable Runnable resultHandler, @Nullable ErrorMes
if (resultHandler != null)
resultHandler.run();
} catch (IOException e) {
e.printStackTrace();
log.error(e.toString());
log.error(ExceptionUtils.getStackTrace(e));
if (errorMessageHandler != null)
errorMessageHandler.handleErrorMessage(e.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void gracefulShutDown(ResultHandler resultHandler) {
try {
ThreadUtils.awaitTasks(tasks, tasks.size(), 120000l); // run in parallel with timeout
} catch (Exception e) {
e.printStackTrace();
log.error("Error awaiting tasks to complete: {}\n", e.getMessage(), e);
}

JsonFileManager.shutDownAllInstances();
Expand Down Expand Up @@ -177,8 +177,7 @@ public void gracefulShutDown(ResultHandler resultHandler) {
}, 1);
}
} catch (Throwable t) {
log.debug("App shutdown failed with exception");
t.printStackTrace();
log.info("App shutdown failed with exception: {}\n", t.getMessage(), t);
PersistenceManager.flushAllDataToDiskAtShutdown(() -> {
resultHandler.handleResult();
log.info("Graceful shutdown resulted in an error. Exiting now.");
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/java/haveno/core/offer/OpenOfferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ private void doProcessPendingOffer(List<OpenOffer> openOffers, OpenOffer openOff
// handle result
resultHandler.handleResult(null);
} catch (Exception e) {
if (!openOffer.isCanceled()) e.printStackTrace();
if (!openOffer.isCanceled()) log.error("Error processing pending offer: {}\n", e.getMessage(), e);
errorMessageHandler.handleErrorMessage(e.getMessage());
}
}).start();
Expand Down Expand Up @@ -1365,9 +1365,8 @@ public void onFault(String errorMessage) {
});
result = true;
} catch (Exception e) {
e.printStackTrace();
errorMessage = "Exception at handleSignOfferRequest " + e.getMessage();
log.error(errorMessage);
log.error(errorMessage + "\n", e);
} finally {
sendAckMessage(request.getClass(), peer, request.getPubKeyRing(), request.getOfferId(), request.getUid(), result, errorMessage);
}
Expand Down Expand Up @@ -1519,8 +1518,7 @@ public void onFault(String errorMessage) {
result = true;
} catch (Throwable t) {
errorMessage = "Exception at handleRequestIsOfferAvailableMessage " + t.getMessage();
log.error(errorMessage);
t.printStackTrace();
log.error(errorMessage + "\n", t);
} finally {
sendAckMessage(request.getClass(), peer, request.getPubKeyRing(), request.getOfferId(), request.getUid(), result, errorMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public Tuple2<Map<String, Long>, Map<String, Long>> getFees() throws IOException
map.put(Config.BTC_TX_FEE, btcTxFee);
map.put(Config.BTC_MIN_TX_FEE, btcMinTxFee);
} catch (Throwable t) {
log.error(t.toString());
t.printStackTrace();
log.error("Error getting fees: {}\n", t.getMessage(), t);
}
return new Tuple2<>(tsMap, map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public synchronized Map<String, MarketPrice> getAll() throws IOException {
long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec"));
marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true));
} catch (Throwable t) {
log.error(t.toString());
t.printStackTrace();
log.error("Error getting all prices: {}\n", t.getMessage(), t);
}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
import monero.wallet.model.MoneroTxWallet;

import javax.annotation.Nullable;

import org.apache.commons.lang3.exception.ExceptionUtils;

import java.math.BigInteger;
import java.security.KeyPair;
import java.time.Instant;
Expand Down Expand Up @@ -523,7 +526,7 @@ protected void handleDisputeOpenedMessage(DisputeOpenedMessage message) {
DisputeValidation.validateSenderNodeAddress(dispute, message.getSenderNodeAddress(), config);
//DisputeValidation.testIfDisputeTriesReplay(dispute, disputeList.getList());
} catch (DisputeValidation.ValidationException e) {
e.printStackTrace();
log.error(ExceptionUtils.getStackTrace(e));
validationExceptions.add(e);
throw e;
}
Expand All @@ -532,9 +535,9 @@ protected void handleDisputeOpenedMessage(DisputeOpenedMessage message) {
try {
DisputeValidation.validatePaymentAccountPayload(dispute); // TODO: add field to dispute details: valid, invalid, missing
} catch (Exception e) {
e.printStackTrace();
log.warn(e.getMessage());
log.error(ExceptionUtils.getStackTrace(e));
trade.prependErrorMessage(e.getMessage());
throw e;
}

// get sender
Expand Down Expand Up @@ -606,9 +609,8 @@ protected void handleDisputeOpenedMessage(DisputeOpenedMessage message) {
}
}
} catch (Exception e) {
e.printStackTrace();
log.error(ExceptionUtils.getStackTrace(e));
errorMessage = e.getMessage();
log.warn(errorMessage);
if (trade != null) trade.setErrorMessage(errorMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void verifySignature(String input,
disputeAgent = arbitratorManager.getDisputeAgentByNodeAddress(nodeAddress).orElse(null);
checkNotNull(disputeAgent, "Dispute agent is null");
} catch (Throwable e) {
e.printStackTrace();
log.error("Error verifying signature: {}\n", e.getMessage(), e);
throw new IllegalArgumentException(Res.get("support.sigCheck.popup.invalidFormat"));
}

Expand All @@ -93,7 +93,7 @@ public static void verifySignature(String input,
throw new IllegalArgumentException(Res.get("support.sigCheck.popup.failed"));
}
} catch (Throwable e) {
e.printStackTrace();
log.error("Error verifying signature with agent pub key ring: {}\n", e.getMessage(), e);
throw new IllegalArgumentException(Res.get("support.sigCheck.popup.invalidFormat"));
}
}
Expand Down
Loading
Loading