-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: thiserror, tracingクレートの導入 #8
Conversation
clocking-server/src/err.rs
Outdated
#[error("initialize tracing subscriber error. {0}")] | ||
InitializeTracingSubscriber(TryInitError), | ||
#[error("create tcp listener error. err: {0}, port: {1}")] | ||
CreateTCPListener(io::Error, u16), | ||
#[error("accept new connection")] | ||
AcceptNewConnection(io::Error), | ||
#[error("accept new stream")] | ||
AcceptNewStream(io::Error), | ||
#[error("private key pem section not found")] | ||
ReadPrivateKeyPEMSection, | ||
#[error("unexpected rust ls error. {0}")] | ||
BuildServer(rustls::Error), | ||
#[error("failed to open file. {0}")] | ||
OpenFile(io::Error), | ||
#[error("failed to read file. {0}")] | ||
ReadFile(io::Error), | ||
#[error("failed to read buffer. {0}")] | ||
ReadBuffer(io::Error), | ||
#[error("failed to convert string. {0}")] | ||
ConvertBuffer(FromUtf8Error), |
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.
ぜ、全体的にエラー文が雑……!
「ReadFile」や「OpenFile」とかのエラーはよくないです
代わりに、LoadPrivateKeyFile
みたいな……意識する場所としては、「それを受けとったユーザーが何をすればいいのか」が分かるように……!
逆にそのようにエラーがまとまってれば、Openで失敗したかReadで失敗したかは割とどうでもいいわけです。
(きっと {0} のように参照される部分で表示されるからね!例えばFailed to load Private Key File: file not found
みたいな)
また、エラー文の末尾にピリオドとかはつけません
いろいろ参考になるかも?
https://doc.rust-jp.rs/rust-by-example-ja/error/multiple_error_types/define_error_type.html
あと、プルリクエスト名がメインブランチへのコミットメッセージになっちゃうのでConventionalに従ってください |
89b8850
to
2e510f5
Compare
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.
LGTM! + 1つ別のIssueに回します(レビュー参照)
Box<dyn Error>
としていた箇所を全て共通のエラーとして処理出来るように発生したエラーをwrap