From: Muhammad Rizki <[email protected]>
To: Alviro Iskandar Setiawan <[email protected]>
Cc: Ammar Faizi <[email protected]>,
GNU/Weeb Mailing List <[email protected]>
Subject: Re: [PATCH v1 2/2] daemon: telegram: Handle MySQL error
Date: Sat, 29 Oct 2022 01:52:53 +0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAOG64qOoL3knPRTVcX+jOopt+24vE0C39Y0Jf1-YAnbGhG7LFQ@mail.gmail.com>
On 29/10/22 01.26, Alviro Iskandar Setiawan wrote:
> On Sat, Oct 29, 2022 at 1:10 AM Muhammad Rizki wrote:
>> On 28/10/22 23.46, Alviro Iskandar Setiawan wrote:
>>> 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.
>>
>> You are right. So we just check every value from the DB method and if
>> it's None just return like goto?
>
> You don't use goto in Python. In an OOP style, the cleanup usually
> happens in the destructor, or in a "try with finally" statement.
>
>>>
>>> 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;
>>>
>>
>> I've improved the remove_patch() earlier using the glob UNIX style path
>> to check if all temp dirs is exists then remove them all. What do you think?
>
> It doesn't address the issue. You still don't understand the
> underlying issue behind your remove_patch() placement.
>
> You have this:
>
> for d, f in files:
> await m.reply_document(f"{d}/{f}", file_name=f)
> await asyncio.sleep(1)
>
> utils.remove_patch(files)
>
> What happens if you follow that for loop, then m.reply_document()
> throws an exception?
It will throw an exception before executing the remove_patch(), but, the
problem is not "if m.reply_document() throw an exception", but the files
variable from the utils.create_template() is the problem if throw an
exception, I think it will be throw a local variable error. Here is my
improved remove_patch():
def remove_patch(
tmp: Union[str, list] = None,
platform: Platform = Platform.TELEGRAM
):
if isinstance(tmp, str):
return shutil.rmtree(tmp)
# check if the tmp is None or an empty list or empty str
# if they are empty or None then remove using glob UNIX
# style path which is if empty will not throw an error
if not bool(tmp):
platform = platform.TELEGRAM.value
store_dir = os.getenv("STORAGE_DIR", "storage")
for d in glob.glob(f"{platform}/{store_dir}/*/"):
shutil.rmtree(d)
return
for d,_ in tmp:
shutil.rmtree(d)
> There are 2 possible solutions, either using a "try with finally"
> statement, or using a destructor wrapped in a class.
I will do it if this PATCH series is done and will do it in logger PATCH
series later. I wait for sir Ammar create the v2 of this series and pull
it after this PATCH series is applied to the master branch.
next prev parent reply other threads:[~2022-10-28 18:52 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-27 15:08 [PATCH v1 0/2] Automatic recovery from a MySQL restart Ammar Faizi
2022-10-27 15:08 ` [PATCH v1 1/2] daemon: telegram: db: Allow the caller to reconnect Ammar Faizi
2022-10-27 16:52 ` Muhammad Rizki
2022-10-27 16:54 ` Muhammad Rizki
2022-10-28 5:48 ` Ammar Faizi
2022-10-27 15:08 ` [PATCH v1 2/2] daemon: telegram: Handle MySQL error Ammar Faizi
2022-10-28 9:21 ` Alviro Iskandar Setiawan
2022-10-28 9:28 ` Ammar Faizi
2022-10-28 9:24 ` Alviro Iskandar Setiawan
2022-10-28 9:32 ` Ammar Faizi
2022-10-28 9:40 ` Alviro Iskandar Setiawan
2022-10-28 9:43 ` Ammar Faizi
2022-10-28 16:29 ` Ammar Faizi
2022-10-28 16:46 ` Alviro Iskandar Setiawan
2022-10-28 16:54 ` Ammar Faizi
2022-10-28 18:10 ` Muhammad Rizki
2022-10-28 18:26 ` Alviro Iskandar Setiawan
2022-10-28 18:52 ` Muhammad Rizki [this message]
2022-10-28 19:08 ` Alviro Iskandar Setiawan
2022-10-28 19:15 ` Muhammad Rizki
2022-10-28 19:29 ` Alviro Iskandar Setiawan
2022-10-28 19:34 ` Ammar Faizi
2022-10-28 19:36 ` Ammar Faizi
2022-10-28 19:38 ` Ammar Faizi
2022-10-28 19:44 ` Muhammad Rizki
2022-10-28 19:39 ` Muhammad Rizki
2022-10-28 19:44 ` Alviro Iskandar Setiawan
2022-10-28 19:46 ` Muhammad Rizki
2022-10-28 19:53 ` Alviro Iskandar Setiawan
2022-10-28 19:16 ` Ammar Faizi
2022-10-28 19:19 ` Muhammad Rizki
2022-10-28 19:19 ` Ammar Faizi
2022-10-28 19:22 ` Muhammad Rizki
2022-10-28 19:33 ` Ammar Faizi
2022-10-28 19:38 ` Muhammad Rizki
2022-10-28 17:02 ` Muhammad Rizki
2022-10-28 17:19 ` Ammar Faizi
2022-10-28 18:15 ` Muhammad Rizki
2022-10-28 18:18 ` Muhammad Rizki
2022-10-28 19:49 ` Ammar Faizi
2022-10-28 19:55 ` Muhammad Rizki
2022-10-28 19:46 ` Ammar Faizi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox