From 771d0bfdf18e0e4111d05a16e879812b61db4159 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Wed, 19 Apr 2023 20:01:11 +0400 Subject: [PATCH] Server: improved error message on server's memory problems (#8130) --- Mage/src/main/java/mage/cards/decks/Deck.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Mage/src/main/java/mage/cards/decks/Deck.java b/Mage/src/main/java/mage/cards/decks/Deck.java index a83b5a51f6..545a0aa185 100644 --- a/Mage/src/main/java/mage/cards/decks/Deck.java +++ b/Mage/src/main/java/mage/cards/decks/Deck.java @@ -137,16 +137,31 @@ public class Deck implements Serializable, Copyable { // Try WORKAROUND for Card DB error: Try to read a card that does exist CardInfo cardInfo = CardRepository.instance.findCard("Silvercoat Lion"); if (cardInfo == null) { - // DB seems to have a problem - try to restart the DB + // DB seems to have a problem - try to restart the DB (useless in 99%) CardRepository.instance.closeDB(); CardRepository.instance.openDB(); cardInfo = CardRepository.instance.findCard("Silvercoat Lion"); Logger.getLogger(Deck.class).error("Tried to restart the DB: " + (cardInfo == null ? "not successful" : "successful")); } - return new GameException("Card not found - " + deckCardInfo.getCardName() + " - " + deckCardInfo.getSetCode() + "/" + deckCardInfo.getCardNum() + " for deck - " + deckName + '\n' - + "Possible reason is, that you use cards in your deck, that are only supported in newer versions of the server.\n" - + "So it can help to use the same card from another set, that's already supported from this server."); + if (cardInfo != null) { + // it's ok, just unknown card + String cardError = String.format("Card not found - %s - %s - %s in deck %s.", + deckCardInfo.getCardName(), + deckCardInfo.getSetCode(), + deckCardInfo.getCardNum(), + deckName + ); + cardError += "\n\nPossible reasons:"; + cardError += "\n - deck problem: un-implemented card or outdated set (fix it by open in deck editor);"; + cardError += "\n - server problem: memory issue (load your deck again or wait a server's restart)."; + return new GameException(cardError); + } else { + // critical error, server must be restarted + // TODO: add auto-retart task here someday (with a docker support) + // see https://github.com/magefree/mage/issues/8130 + return new GameException("Problems detected on the server side (memory issue), wait for a restart."); + } } private static Card createCard(DeckCardInfo deckCardInfo, boolean mockCards, Map cardInfoCache) {