-
Notifications
You must be signed in to change notification settings - Fork 597
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
fuo协议Show命令增强-Add Features #380
Conversation
fuocore/cmds/show.py
Outdated
try: | ||
song = provider.Song.get(sid) | ||
except AttributeError: | ||
return "No such provider : {}-{}".format(provider.name, provider_path_name) | ||
# marshallow exception -- Validation Error | ||
except Exception: | ||
return "song identified by {} is unavailable in {} ".format(sid, provider.name) | ||
else: | ||
if song is None: | ||
return "song {} is not in local library".format(sid) | ||
return song |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
下面有几段代码都比较相似,可以考虑抽象一下 ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好嘞,我先想着看看
fuocore/cmds/show.py
Outdated
except Exception: | ||
return "song identified by {} is unavailable in {} ".format(sid, provider.name) | ||
else: | ||
if song is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果 song 是 None,直接返回个 None 是不是就可以了?用 None 来表示 id 找不到对应的歌曲。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
啊的确如此,但是最终呈现在客户端的命令结果什么也没有,身为用户我可能不清楚该命令是否成功执行,所以选择了返回一个提示
非常感谢 ~ 今天下班后我会继续 review 下 ~ |
except NotFound: | ||
# pass it to the exception handle procedure in __init__.py | ||
raise | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里只是 re-raise 了一下,看起来 try ... except...
不是很有必要?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对,代码删改到后面,变成这一段只是为了使得__init__.py能捕获得异常的信息,所以就简单的re-raise,应该有更好的方法来着
# use backstrace lib (the format_exc/print_exc) causes fail | ||
# maybe the coroutine issue ? | ||
uri_msg = "Bad Uri Exception: fuo://{}".format(self.rule) | ||
return uri_msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我觉得可以直接在抛错的时候把文字内容加进去,比如
raise NotFound(f"Bad Uri Exception: fuo://{self.rule}")
@@ -3,10 +3,22 @@ | |||
from urllib.parse import parse_qsl, urlsplit | |||
|
|||
|
|||
class NotFound(Exception): | |||
class ShowCmdException(Exception): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
赞
@@ -66,6 +68,9 @@ def exec_cmd(cmd, *args, app): | |||
playlist=playlist, | |||
live_lyric=live_lyric) | |||
rv = handler.handle(cmd) | |||
except ShowCmdException: | |||
logger.exception('handle cmd({}) error'.format(cmd)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
像这种已经被正确处理了的错误,打个 warning/error 级别就可以了。
打 exception 的话,一般是意料之外的错误。比如未知的错误等。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
谢谢,学习到了
整体挺棒的! 代码有个别地方可以稍微优化下,我等下 merge 之后再改下吧。 |
Issue #317