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

feat: add translation error handling #516

Conversation

GwanLiZa
Copy link
Contributor

@GwanLiZa GwanLiZa commented Nov 16, 2024

Summary by CodeRabbit

  • 신규 기능
    • 번역 기능에서 오류 처리 개선: 번역 요청 중 발생할 수 있는 예외를 처리하고, 오류 발생 시 사용자에게 알림을 표시합니다.
  • 버그 수정
    • 번역 결과 처리에서 오류 케이스 추가: 번역 실패 시 오류 메시지를 포함한 알림을 표시하여 사용자 경험을 향상시킵니다.
  • 기타
    • 버전 업데이트: 애플리케이션 버전이 4.1.3에서 4.1.4로 변경되었습니다.

@GwanLiZa GwanLiZa requested a review from a team November 16, 2024 14:30
Copy link
Contributor

coderabbitai bot commented Nov 16, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

이 변경 사항은 NoticeEditBodyPageNoticeWriteBodyPage 클래스의 _translate 메서드에 대한 오류 처리 개선을 포함합니다. 새로운 구현은 위젯의 장착 상태를 확인한 후 번역 요청의 결과를 처리하도록 하여, 위젯이 더 이상 위젯 트리에 속하지 않을 때 발생할 수 있는 오류를 방지합니다. 또한, 번역 과정 중 오류가 발생할 경우 사용자에게 오류 메시지를 포함한 토스트 알림을 표시하여 사용자 피드백을 향상시켰습니다.

Changes

파일 경로 변경 요약
lib/app/modules/notices/presentation/pages/... NoticeEditBodyPageNoticeWriteBodyPage_translate 메서드에서 오류 처리 개선. 위젯 장착 상태 확인 및 오류 발생 시 토스트 메시지 표시 기능 추가.
pubspec.yaml 버전 번호를 4.1.3에서 4.1.4로 업데이트.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • 2paperstar
  • dawnfire05

🐰 변화의 노래를 불러요,
오류를 잡고, 토스트로 전해요.
번역이 더 안전해졌어요,
사용자에게 기쁨을 주는 길로!
함께 뛰어놀며 더 나은 세상,
우리 모두의 꿈이 이루어져요! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 20703c4 and 1efaf88.

📒 Files selected for processing (3)
  • lib/app/modules/notices/presentation/pages/notice_edit_body_page.dart (1 hunks)
  • lib/app/modules/notices/presentation/pages/notice_write_body_page.dart (1 hunks)
  • pubspec.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • pubspec.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/app/modules/notices/presentation/pages/notice_edit_body_page.dart
  • lib/app/modules/notices/presentation/pages/notice_write_body_page.dart

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
lib/app/modules/notices/presentation/pages/notice_edit_body_page.dart (1)

284-307: 오류 처리 구현이 개선되었습니다.

번역 기능의 오류 처리가 체계적으로 구현되었습니다. 다만 몇 가지 개선 사항을 제안드립니다:

  1. 일반적인 예외 메시지는 사용자가 이해하기 어려울 수 있습니다. 사용자 친화적인 오류 메시지를 표시하는 것이 좋겠습니다.
  2. 오류가 발생했을 때 분석 이벤트를 추가하면 문제 추적에 도움이 될 것 같습니다.

다음과 같이 개선하는 것을 제안드립니다:

 try {
   final bloc = context.read<AiBloc>();
   final blocker = bloc.stream.firstWhere((s) => s.hasResult);
   bloc.add(AiEvent.request(
     body: _koreanBodyController.html,
     lang: Language.en,
   ));
   final result = await blocker;
   if (!mounted) return;
   result.mapOrNull(
     loaded: (result) {
       AnalyticsRepository.action(
           const AnalyticsEvent.noticeEditBodyUseAiTranslation());
       return _englishBodyController.html = result.body;
     },
     error: (error) {
       context.showToast(error.message);
+      AnalyticsRepository.error(
+          const AnalyticsEvent.noticeEditBodyTranslationError());
     },
   );
 } catch (e) {
   if (mounted) {
-    context.showToast(e.toString());
+    context.showToast(context.t.notice.translation.error);
+    AnalyticsRepository.error(
+        const AnalyticsEvent.noticeEditBodyTranslationError());
   }
 }
lib/app/modules/notices/presentation/pages/notice_write_body_page.dart (1)

332-350: 기본적인 오류 처리가 잘 구현되었습니다.

오류 처리 로직이 추가되어 사용자 경험이 개선되었습니다. 다만 다음과 같은 개선사항을 제안드립니다:

  1. 구체적인 예외 타입에 따른 처리
  2. 디버깅을 위한 로깅 추가
  3. 재시도 메커니즘 구현 검토

다음과 같이 개선해 보시는 것은 어떨까요:

 Future<void> _translate() async {
   try {
     final bloc = context.read<AiBloc>();
     final blocker = bloc.stream.firstWhere((s) => s.hasResult);
     bloc.add(AiEvent.request(
       body: _koreanBodyController.html,
       lang: Language.en,
     ));
     final result = await blocker;
     result.mapOrNull(
       loaded: (result) => _englishBodyController.html = result.body,
       error: (error) {
+        debugPrint('Translation error: ${error.message}');
         context.showToast(error.message);
       },
     );
   } catch (e) {
+    debugPrint('Unexpected error during translation: $e');
     if (mounted) {
-      context.showToast(e.toString());
+      context.showToast(context.t.common.unexpectedError);
     }
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2a3d90c and 607d7a7.

📒 Files selected for processing (2)
  • lib/app/modules/notices/presentation/pages/notice_edit_body_page.dart (1 hunks)
  • lib/app/modules/notices/presentation/pages/notice_write_body_page.dart (1 hunks)

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 16, 2024
Copy link
Member

@2paperstar 2paperstar left a comment

Choose a reason for hiding this comment

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

try catch 로 에러가 나가진 않아요! mapOrNull해서 토스트만 띄워주면 충분!

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 16, 2024
2paperstar
2paperstar previously approved these changes Nov 16, 2024
Copy link
Member

@2paperstar 2paperstar left a comment

Choose a reason for hiding this comment

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

개취긴 한데.. ㅎㅎ

@2paperstar
Copy link
Member

이 PR에 4.1.4 로 버전 업그레이드 하는거 넣어주시구 머지 후에 배포해주세요!

@GwanLiZa GwanLiZa merged commit 5ec35b1 into gsainfoteam:development Nov 16, 2024
5 checks passed
@2paperstar 2paperstar linked an issue Nov 17, 2024 that may be closed by this pull request
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.

[PROPOSAL] add translation error handling
2 participants