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

fuo协议Show命令增强-Add Features #380

Merged
merged 9 commits into from
Jul 2, 2020
Merged

Conversation

Heersin
Copy link
Contributor

@Heersin Heersin commented Jul 1, 2020

Issue #317

  • 支持更多路由
    • fuo:///artists//albums 展示歌手的所有专辑
    • fuo:///users/me 展示当前登录的用户的信息
  • 添加部分错误处理

Comment on lines 51 to 61
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
Copy link
Member

Choose a reason for hiding this comment

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

下面有几段代码都比较相似,可以考虑抽象一下 ~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好嘞,我先想着看看

except Exception:
return "song identified by {} is unavailable in {} ".format(sid, provider.name)
else:
if song is None:
Copy link
Member

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 找不到对应的歌曲。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

啊的确如此,但是最终呈现在客户端的命令结果什么也没有,身为用户我可能不清楚该命令是否成功执行,所以选择了返回一个提示

@coveralls
Copy link

coveralls commented Jul 1, 2020

Coverage Status

Coverage decreased (-0.08%) to 33.832% when pulling a64deeb on Heersin:dev into 4f1feb2 on feeluown:master.

@cosven
Copy link
Member

cosven commented Jul 2, 2020

非常感谢 ~ 今天下班后我会继续 review 下 ~

except NotFound:
# pass it to the exception handle procedure in __init__.py
raise
return None
Copy link
Member

Choose a reason for hiding this comment

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

这里只是 re-raise 了一下,看起来 try ... except... 不是很有必要?

Copy link
Contributor Author

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
Copy link
Member

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):
Copy link
Member

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))
Copy link
Member

Choose a reason for hiding this comment

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

像这种已经被正确处理了的错误,打个 warning/error 级别就可以了。

打 exception 的话,一般是意料之外的错误。比如未知的错误等。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

谢谢,学习到了

@cosven
Copy link
Member

cosven commented Jul 2, 2020

整体挺棒的!

代码有个别地方可以稍微优化下,我等下 merge 之后再改下吧。
因为我感觉是老代码的结构有些不是很合理。

@cosven cosven merged commit 66f17fd into feeluown:master Jul 2, 2020
@cosven cosven mentioned this pull request Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants