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

에러 처리 구조화 #26

Closed
2 tasks
EATSTEAK opened this issue Mar 26, 2025 · 4 comments · Fixed by #39
Closed
2 tasks

에러 처리 구조화 #26

EATSTEAK opened this issue Mar 26, 2025 · 4 comments · Fixed by #39
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@EATSTEAK
Copy link
Member

📄 설명

에러 처리를 구조화하기

프로포절

✅ 작업할 내용

  • 스펙 확정하기(~금)
  • 구현하기(~월)

🙋🏻 참고 자료

No response

@EATSTEAK EATSTEAK added the enhancement New feature or request label Mar 26, 2025
@EATSTEAK EATSTEAK added this to the PoC milestone Mar 26, 2025
@EATSTEAK EATSTEAK added this to ssufid Mar 26, 2025
@EATSTEAK EATSTEAK moved this to Ready in ssufid Mar 26, 2025
@EATSTEAK EATSTEAK moved this from Ready to Backlog in ssufid Mar 27, 2025
@cometj03
Copy link
Member

에러 처리 요구사항

  • 플러그인에서 발생한 에러
    • plugin -> core -> daemon으로 자연스럽게 전파되도록 하기
    • 포함되어야 할 정보
      • 에러의 종류
      • 에러가 발생한 원인
      • 플러그인 식별자(어느 플러그인에서 난 오류인지)
    • 고민해야 할 것
      • 플러그인에서 에러 타입을 커스텀 할 수 있게 할지
      • core에서 플러그인 에러 종류까지 모두 정의해둘지
  • core에서 발생한 에러도 마찬가지로 별다른 처리 없이 core -> daemon으로 전파될 수 있게

@cometj03
Copy link
Member

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 Plugin

struct 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 메서드 구현
}

@EATSTEAK
Copy link
Member Author

EATSTEAK commented Mar 29, 2025

@cometj03 제안대로 구현한다면 SsufidCore::run 함수는 그대로 SsufidError를 반환하게 되나요? SsufidPluginError -> SsufidError 사이의 손실 변환이 되는게 걸리네요.

++ SsufidPluginError는 Error를 구현해야할듯요.

저도 지금 프로포절 작성중...

대충 요약

  • Comet 것과 비슷
  • 하지만 SsufidError::Plugin 에 kind 필드를 두고, `SsufidPluginErrorKind 에 일어날 수 있는 문제를 두고, Custom variant도 넣어두면 좋을 것 같아요.

@EATSTEAK
Copy link
Member Author

https://github.com/serde-rs/json/blob/8a56cfa6d0a93c39ee4ef07d431de0748eed9028/src/error.rs#L21

serde_json은 에러를 가볍게 만들기 위해서 Box 타입을 만들고 그 내부에 실제 구현을 넣어두었네요.

@EATSTEAK EATSTEAK moved this from Backlog to In progress in ssufid Mar 29, 2025
@EATSTEAK EATSTEAK moved this from In progress to In review in ssufid Mar 29, 2025
@github-project-automation github-project-automation bot moved this from In review to Done in ssufid Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants