Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add log error for ping exception #61

Merged
merged 5 commits into from
Aug 6, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/wechaty_puppet_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import socket
from logging import Logger
from typing import Optional, Tuple
from ping3 import ping # type: ignore
from ping3 import ping, errors # type: ignore
from wechaty_puppet.exceptions import WechatyPuppetConfigurationError # type: ignore


Expand Down Expand Up @@ -58,7 +58,14 @@ def test_endpoint(end_point: str, log: Logger) -> int:

res = True
if port is None:
if ping(host) is False:
try:
if ping(host) is False:
res = False
except PermissionError as pe:
log.error(pe)
res = False
except errors.PingError as e:
log.error(f'got a ping error:\n{e}')
res = False
Comment on lines 73 to 82
Copy link
Collaborator

@wj-Mcat wj-Mcat Aug 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your improvement look so great to me. But I don't know in what situation the error will be raised. Can add some more detailed test case for PermissionError and PingError to help us understand the code ? If you can, it's great docs for developer to understand more about endpoint. How do you think about it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for replay. :-)

There will be a PermissionError, when I set end_point to a service name and run script on a Linux machine without root. And without above codes, due to the outer try catch, I only got Wechaty - ERROR - The network is not good, the bot will try to restart after 60 seconds., which make people confusing. There need more message for figuring out the true problem, so I add try catch for ping call and print possible exception message.

By the way, I optimized the comment.

else:
try:
Expand Down