From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,NO_DNS_FOR_FROM autolearn=ham autolearn_force=no version=3.4.6 Received: from [10.7.7.5] (unknown [182.253.183.184]) by gnuweeb.org (Postfix) with ESMTPSA id 092F47E24F; Sat, 24 Dec 2022 21:22:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671916932; bh=eGESPnKXTvibE9WpwHw4DsWYhdm9HwF7ylV+qAcMfwQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=c1PR7mYW5/p+weNbEcJMbYTG1WpS3hyWpyKdKmeoR3KcBJ9eZWN1Mqy/nFhydZ6kz OINlbui+s63As4Y8ca6FwwBnYu4WVafnYZbWTlSvOVe4dQ6rXHe4SxuIfjRvHnkoct 4f9WWZQaKdoyeh3/ZZq+uaSZ5SFJpp8QtC66y6JZc2e4YZM6n45+rcss18bn5tiW9B I5UlDk3paeIE5xO7xHCnLjJhdAg1BbiAAPZzUJo8m9ylgb9hoVSUYXuD6d6vOo7iqM WFiZ+U5XDXruiYfdTNEpSDBiAuVzbORjFDtdNPNRbUca0NwxQypAg/YwqW67+kJyIN f2Mxvc90InwrQ== Message-ID: Date: Sun, 25 Dec 2022 04:22:08 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v4 12/17] telegram: Implement the log message for catching errors Content-Language: en-US To: Muhammad Rizki Cc: Alviro Iskandar Setiawan , GNU/Weeb Mailing List References: <20221221013347.1704-1-kiizuha@gnuweeb.org> <20221221013347.1704-13-kiizuha@gnuweeb.org> From: Ammar Faizi In-Reply-To: <20221221013347.1704-13-kiizuha@gnuweeb.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: On 12/21/22 8:33 AM, Muhammad Rizki wrote: > @@ -63,14 +63,17 @@ class Bot(): > > > async def __run(self): > - print("[__run]: Running...") > + self.logger.info("Running...") > try: > for url in self.db.get_atom_urls(): > await self.__handle_atom_url(url) > except (OperationalError, DatabaseError) as e: > await self.handle_db_error(e) > except: > - print(traceback.format_exc()) > + exc_str = utils.catch_err() > + self.logger.warning(exc_str) > + capt = "Unkown raw lore URL, see full details in the log file." > + await self.client.send_log_file(capt) At this point, @url may or may not be defined. If self.db.get_atom_urls() succeeds and return more than 0 result(s), @url is defined. > if not self.isRunnerFixed: > self.isRunnerFixed = True > @@ -86,8 +89,13 @@ class Bot(): > async def __handle_atom_url(self, url): > urls = await self.scraper.get_new_threads_urls(url) > for url in urls: > - mail = await self.scraper.get_email_from_url(url) > - await self.__handle_mail(url, mail) > + try: > + mail = await self.scraper.get_email_from_url(url) > + await self.__handle_mail(url, mail) > + except: > + exc_str = utils.catch_err() > + self.logger.warning(exc_str) > + await self.client.send_log_file(url) This part is problematic, if you have MySQL error here, the previous 'try and except' statement won't catch it because it's already caught by your error logging. Your error logging kills the recovery function that the caller function ('__run') provides. -- Ammar Faizi