From 0c3cdb12f8f6ea9f56c4ba29e94b1c8cd751d5c7 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 4 Jun 2010 15:59:47 +0800 Subject: [PATCH] General cleanup - Exception messages and improved logging. Stars HHC, HHC itself and Hand. Should not get the first 100 characters of an failing hand in the log, which contains the handid for later reference. Played around with the number of characters a while ago - 100 chars is about the sweet spot. --- pyfpdb/Hand.py | 11 ++++++----- pyfpdb/HandHistoryConverter.py | 6 ++---- pyfpdb/PokerStarsToFpdb.py | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index adb7d3f6..71fc6ced 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -274,15 +274,16 @@ If a player has None chips he won't be added.""" self.streets.update(match.groupdict()) log.debug("markStreets:\n"+ str(self.streets)) else: + tmp = self.handText[0:100] log.error("markstreets didn't match") log.error(" - Assuming hand cancelled") self.cancelled = True - raise FpdbParseError + raise FpdbParseError("FpdbParseError: markStreets appeared to fail: First 100 chars: '%s'" % tmp) def checkPlayerExists(self,player): if player not in [p[1] for p in self.players]: - print "checkPlayerExists", player, "fail" - raise FpdbParseError + print "DEBUG: checkPlayerExists %s fail" % player + raise FpdbParseError("checkPlayerExists: '%s' failed." % player) @@ -1487,9 +1488,9 @@ class Pot(object): if self.sym is None: self.sym = "C" if self.total is None: - print "call Pot.end() before printing pot total" + print "DEBUG: call Pot.end() before printing pot total" # NB if I'm sure end() is idempotent, call it here. - raise FpdbParseError + raise FpdbParseError("FpdbError in printing Hand object") ret = "Total pot %s%.2f" % (self.sym, self.total) if len(self.pots) < 2: diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 5b65b955..3b858f10 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -137,8 +137,7 @@ Otherwise, finish at EOF. self.numHands += 1 except FpdbParseError, e: self.numErrors += 1 - log.warning("Failed to convert hand %s" % e.hid) - log.warning("Exception msg: '%s'" % str(e)) + log.warning("HHC.start(follow): processHand failed: Exception msg: '%s'" % e) log.debug(handText) else: handsList = self.allHandsAsList() @@ -152,8 +151,7 @@ Otherwise, finish at EOF. self.processedHands.append(self.processHand(handText)) except FpdbParseError, e: self.numErrors += 1 - log.warning("Failed to convert hand %s" % e.hid) - log.warning("Exception msg: '%s'" % str(e)) + log.warning("HHC.start(): processHand failed: Exception msg: '%s'" % e) log.debug(handText) self.numHands = len(handsList) endtime = time.time() diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 79bef1ea..17a9b15c 100644 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -140,7 +140,7 @@ class PokerStars(HandHistoryConverter): tmp = handText[0:100] log.error("determineGameType: Unable to recognise gametype from: '%s'" % tmp) log.error("determineGameType: Raising FpdbParseError") - raise FpdbParseError + raise FpdbParseError("Unable to recognise gametype from: '%s'" % tmp) mg = m.groupdict() # translations from captured groups to fpdb info strings @@ -194,7 +194,7 @@ class PokerStars(HandHistoryConverter): except KeyError: log.error("determineGameType: Lim_Blinds has no lookup for '%s'" % mg['BB']) log.error("determineGameType: Raising FpdbParseError") - raise FpdbParseError + raise FpdbParseError("Lim_Blinds has no lookup for '%s'" % mg['BB']) # NB: SB, BB must be interpreted as blinds or bets depending on limit type. return info