-
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
에러 처리 구조화 #26
Comments
에러 처리 요구사항
|
Comet 제안Core 모듈에서 에러 타입 정의pub enum SsufidError {
// 플러그인에서 발생한 에러는 모두 SsufidError::Plugin으로 변환됨
Plugin(String),
// 기타 core 에러 타입들
// ...
}
pub trait SsufidPluginError {
fn msg(&self) -> String;
}
// SsufidPluginError를 구현한 에러 타입에 대해 From 트레이트 구현
impl<T> From<T> for SsufidError
where
T: SsufidPluginError
{
fn from(plugin_error: T) -> Self {
SsufidError::Plugin(plugin_error.msg())
}
}
// SsufidPlugin 트레이트에서 에러 연관 타입 추가
pub trait SsufidPlugin {
// const ...
type Error: SsufidPluginError;
async fn crawl(&self, posts_limit: u32) -> Result<Vec<SsufidPost>, Self::Error>;
} 사용 예시: SsuCatch Pluginstruct SsuCatchError {
id: String
kind: String,
error: Box<dyn std::error::Error>,
}
impl SsufidPluginError for SsuCatchError {
fn msg(&self) -> String { ... }
}
struct SsuCatchPlugin {};
impl SsufidPlugin for SsuCatchPlugin {
// ...
type Error = SsuCatchError;
// crawl 메서드 구현
} |
@cometj03 제안대로 구현한다면 ++ 저도 지금 프로포절 작성중... 대충 요약
|
https://github.com/serde-rs/json/blob/8a56cfa6d0a93c39ee4ef07d431de0748eed9028/src/error.rs#L21 serde_json은 에러를 가볍게 만들기 위해서 Box 타입을 만들고 그 내부에 실제 구현을 넣어두었네요. |
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
📄 설명
에러 처리를 구조화하기
프로포절
✅ 작업할 내용
🙋🏻 참고 자료
No response
The text was updated successfully, but these errors were encountered: