improve error handling

show error popup on error initializing trade
instruct to close monero-wallet-rpc on error opening wallets
throw error if trade missing wallet on init or failure to sign payout tx
This commit is contained in:
woodser 2023-04-26 08:56:52 -04:00
parent 4cf6992113
commit 6d2819bde7
4 changed files with 31 additions and 23 deletions

View File

@ -329,14 +329,19 @@ public abstract class Trade implements Tradable, Model {
@Setter @Setter
private long takeOfferDate; private long takeOfferDate;
// Initialization
private static final int TOTAL_INIT_STEPS = 15; // total estimated steps
private int initStep = 0;
@Getter
private double initProgress = 0;
@Getter
@Setter
private Exception initError;
// Mutable // Mutable
private long amount; private long amount;
@Setter @Setter
private long price; private long price;
private int initStep = 0;
private static final int TOTAL_INIT_STEPS = 15; // total estimated steps
@Getter
private double initProgress = 0;
@Nullable @Nullable
@Getter @Getter
private State state = State.PREPARATION; private State state = State.PREPARATION;
@ -673,7 +678,7 @@ public abstract class Trade implements Tradable, Model {
// sync wallet if applicable // sync wallet if applicable
if (!isDepositRequested() || isPayoutUnlocked()) return; if (!isDepositRequested() || isPayoutUnlocked()) return;
if (!walletExists()) log.warn("Missing trade wallet for {} {}", getClass().getSimpleName(), getId()); if (!walletExists()) throw new IllegalStateException("Missing trade wallet for " + getClass().getSimpleName() + " " + getId());
if (xmrWalletService.getConnectionsService().getConnection() == null || Boolean.FALSE.equals(xmrWalletService.getConnectionsService().isConnected())) return; if (xmrWalletService.getConnectionsService().getConnection() == null || Boolean.FALSE.equals(xmrWalletService.getConnectionsService().isConnected())) return;
updateSyncing(); updateSyncing();
} }
@ -1006,18 +1011,9 @@ public abstract class Trade implements Tradable, Model {
if (sign) { if (sign) {
// sign tx // sign tx
try { MoneroMultisigSignResult result = wallet.signMultisigTxHex(payoutTxHex);
MoneroMultisigSignResult result = wallet.signMultisigTxHex(payoutTxHex); if (result.getSignedMultisigTxHex() == null) throw new RuntimeException("Error signing payout tx");
if (result.getSignedMultisigTxHex() == null) throw new RuntimeException("Error signing payout tx"); payoutTxHex = result.getSignedMultisigTxHex();
payoutTxHex = result.getSignedMultisigTxHex();
} catch (Exception e) {
if (getPayoutTxHex() != null) {
log.info("Reusing previous payout tx for {} {} because signing failed with error \"{}\"", getClass().getSimpleName(), getId(), e.getMessage()); // in case previous message with signed tx failed to send
payoutTxHex = getPayoutTxHex();
} else {
throw e;
}
}
// describe result // describe result
describedTxSet = wallet.describeMultisigTxSet(payoutTxHex); describedTxSet = wallet.describeMultisigTxSet(payoutTxHex);

View File

@ -427,8 +427,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
} }
} catch (Exception e) { } catch (Exception e) {
log.warn("Error initializing {} {}: {}", trade.getClass().getSimpleName(), trade.getId(), e.getMessage()); log.warn("Error initializing {} {}: {}", trade.getClass().getSimpleName(), trade.getId(), e.getMessage());
e.printStackTrace(); trade.setInitError(e);
trade.prependErrorMessage(e.getMessage());
} }
}); });
}; };

View File

@ -232,10 +232,14 @@ public class XmrWalletService {
public MoneroWalletRpc openWallet(String walletName) { public MoneroWalletRpc openWallet(String walletName) {
log.info("{}.openWallet({})", getClass().getSimpleName(), walletName); log.info("{}.openWallet({})", getClass().getSimpleName(), walletName);
if (isShutDownStarted) throw new IllegalStateException("Cannot open wallet because shutting down"); if (isShutDownStarted) throw new IllegalStateException("Cannot open wallet because shutting down");
return openWalletRpc(new MoneroWalletConfig() try {
.setPath(walletName) return openWalletRpc(new MoneroWalletConfig()
.setPassword(getWalletPassword()), .setPath(walletName)
null); .setPassword(getWalletPassword()),
null);
} catch (MoneroError e) {
throw new IllegalStateException("Could not open wallet '" + walletName + "'. Please close Haveno, stop all monero-wallet-rpc processes, and restart Haveno.");
}
} }
/** /**

View File

@ -220,6 +220,15 @@ public class MainViewModel implements ViewModel, HavenoSetup.HavenoSetupListener
tradeManager.applyTradePeriodState(); tradeManager.applyTradePeriodState();
tradeManager.getObservableList().forEach(trade -> { tradeManager.getObservableList().forEach(trade -> {
// check initialization error
if (trade.getInitError() != null) {
new Popup().warning("Error initializing trade" + " " + trade.getShortId() + "\n\n" +
trade.getInitError().getMessage())
.show();
}
// check trade period
Date maxTradePeriodDate = trade.getMaxTradePeriodDate(); Date maxTradePeriodDate = trade.getMaxTradePeriodDate();
String key; String key;
switch (trade.getPeriodState()) { switch (trade.getPeriodState()) {