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=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by gnuweeb.org (Postfix) with ESMTPSA id 83ADF804FD for ; Fri, 28 Oct 2022 16:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1666975621; bh=m6GpwpAYkBgbLPebDAc+NyqeFiCEr7LxeNid36oFRA0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=IwU+zR4OG1sDVMDMQHkm2EC+HsK9XeJLnkeFo4aYcWNXKH2UWX+ertThu+u723Up8 /pgbffYejzQ3Txwg2+IBdyxC6bpiL8I2B7AI+smh3Bn5vS2y43woyagy6yC485ivEl EYqGE0U/CExLMMl8ZEUSK7elyogzpTh6wlwW2gDwhzBFtvJq5nazJUskPA47AU6OTq kK75XOylqaXqOu94ugIDM0/ImKrMAHVTo/snztVQYKgpiF1SxFXwrXTh0bmdgTPFAr 97PJwLZFb+jerXv/GM4T+5TOwZqYLRULqgtiCHnIAQyCpTbov3CsiQZlFWz273iGx+ uF1s4bWoP2HqA== Received: by mail-lj1-f172.google.com with SMTP id s24so9041398ljs.11 for ; Fri, 28 Oct 2022 09:47:01 -0700 (PDT) X-Gm-Message-State: ACrzQf1ETrX1jSGbUfz8sOYLLRmJ9PS91fx4lzF3OagInZRuPjvt3pQB rpCQ5fCfzphT+v3MzVUbZF3Im7lnT2BHWXojdf4= X-Google-Smtp-Source: AMsMyM7shN8bKbUkSgTU6gcLoyjQHoPrHPNEjeB/yCNg239Du7OBjEsKNAhqYRYRZCD+VbUo+HGunUdjV1ZP5dPASf0= X-Received: by 2002:a2e:7816:0:b0:276:ffbf:2f09 with SMTP id t22-20020a2e7816000000b00276ffbf2f09mr153436ljc.349.1666975614685; Fri, 28 Oct 2022 09:46:54 -0700 (PDT) MIME-Version: 1.0 References: <20221027150823.601914-1-ammarfaizi2@gnuweeb.org> <20221027150823.601914-3-ammarfaizi2@gnuweeb.org> <1d500d37-b11b-75fd-38e5-d7f8e0a9b1d4@gnuweeb.org> <3a79a587-ddee-9e25-2ac5-b573938b44a9@gnuweeb.org> <043f55c3-67d8-9130-aca4-73c59926d2af@gnuweeb.org> In-Reply-To: <043f55c3-67d8-9130-aca4-73c59926d2af@gnuweeb.org> From: Alviro Iskandar Setiawan Date: Fri, 28 Oct 2022 23:46:43 +0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 2/2] daemon: telegram: Handle MySQL error To: Ammar Faizi Cc: "GNU/Weeb Mailing List" , Muhammad Rizki Content-Type: text/plain; charset="UTF-8" List-Id: On Fri, Oct 28, 2022 at 11:29 PM Ammar Faizi wrote: > I believe there are more issues like this somewhere else. But this is > the most hot path to get spotted. We also have to teach Rizki about this > so he can fix it himself. Yes. > if is_patch: > m: "Message" = await self.client.send_patch_email( > mail, tg_chat_id, text, reply_to, url > ) > else: > text = "#ml\n" + text > m: "Message" = await self.client.send_text_email( > tg_chat_id, text,reply_to, url > ) > > self.db.save_telegram_mail(email_id, m.chat.id, m.id) > for d, f in files: > await m.reply_document(f"{d}/{f}", file_name=f) > await asyncio.sleep(1) > > utils.remove_patch(files) > > return True Even this part is also problematic, if you hit an error before utils.remove_patch(), the patch file won't get removed because exception will stop the current execution and throw the exception to the previous call stack. I hate try and catch style, because it's very easy to miss an error like this. I prefer the way C handles error manually via return value like: ret = func_call(); if (ret < 0) goto clean_up; But that's obviously not the Python style. Python prefers using exceptions which make the caller may not be aware of this cleanup strategy! -- Viro