Skip to content

feat: enhance error handling with unified error types, logging, and i18n support#13

Merged
otomatty merged 2 commits intodevelopfrom
feature/error-handling-enhancement
Nov 19, 2025
Merged

feat: enhance error handling with unified error types, logging, and i18n support#13
otomatty merged 2 commits intodevelopfrom
feature/error-handling-enhancement

Conversation

@otomatty
Copy link
Copy Markdown
Owner

概要

Phase 6.5のエラーハンドリング強化を実装しました。統一的なエラータイプ、構造化ログ、i18n対応のエラーメッセージ、エラーバウンダリーの改善を行いました。

実装内容

1. エラータイプとエラークラスの作成

  • lib/errors/types.ts: アプリケーション全体で使用するエラータイプとインターフェース定義
  • lib/errors/server.ts: サーバーサイド用のエラークラス(DatabaseError, ValidationError, NotFoundError等)
  • lib/errors/client.ts: クライアントサイド用のエラークラス(NetworkError等)

2. エラーログ機能の実装

  • lib/errors/logger.ts: 構造化されたエラーログ機能
    • 開発環境と本番環境で異なるログ出力
    • サーバーサイドとクライアントサイドのログ実装

3. エラーハンドリングユーティリティ

  • lib/errors/handler.ts: Server Actions用のエラーハンドリングラッパー
    • handleServerAction: 統一的なエラーハンドリング
    • handleDatabaseAction: データベース操作用のエラーハンドリング

4. エラーメッセージの国際化

  • public/locales/ja/errors.json: 日本語エラーメッセージ
  • public/locales/en/errors.json: 英語エラーメッセージ
  • lib/errors/i18n.ts: エラーメッセージのi18nユーティリティ
  • lib/i18n/i18n.settings.ts: errors名前空間を追加

5. エラーバウンダリーの改善

  • app/error.tsx: i18n対応、エラーログ記録、開発環境での詳細情報表示
  • app/global-error.tsx: i18n対応、エラーログ記録
  • hooks/useErrorHandler.ts: AppError型の修正、i18n対応のエラーメッセージ表示

6. Server Actionsのエラーハンドリング統一

すべてのServer Actionsファイルに統一的なエラーハンドリングを適用:

  • actions/issues.ts
  • actions/users.ts
  • actions/teams.ts
  • actions/projects.ts
  • actions/labels.ts
  • actions/priorities.ts
  • actions/status.ts

変更ファイル

新規作成

  • lib/errors/types.ts
  • lib/errors/server.ts
  • lib/errors/client.ts
  • lib/errors/logger.ts
  • lib/errors/handler.ts
  • lib/errors/i18n.ts
  • lib/errors/index.ts
  • public/locales/ja/errors.json
  • public/locales/en/errors.json

変更

  • actions/issues.ts
  • actions/users.ts
  • actions/teams.ts
  • actions/projects.ts
  • actions/labels.ts
  • actions/priorities.ts
  • actions/status.ts
  • app/error.tsx
  • app/global-error.tsx
  • hooks/useErrorHandler.ts
  • lib/i18n/i18n.settings.ts

関連Issue

  • #3 - [Phase 6.5] エラーハンドリングの強化

テスト

  • リンターエラーなし
  • すべてのServer Actionsでエラーハンドリングが統一されている
  • エラーメッセージがi18n対応されている

注意事項

  • エラーメッセージは日本語と英語の両方で提供されています
  • 開発環境では詳細なエラー情報が表示されます
  • 本番環境では詳細情報が制限されます

…18n support

- Add error types and error classes (lib/errors/types.ts, server.ts, client.ts)
- Implement structured error logging (lib/errors/logger.ts)
- Add error handling utilities for Server Actions (lib/errors/handler.ts)
- Add i18n support for error messages (public/locales/{ja,en}/errors.json)
- Improve error boundaries (app/error.tsx, app/global-error.tsx)
- Update useErrorHandler hook with i18n support
- Unify error handling across all Server Actions
- Add errors namespace to i18n settings

This implements Phase 6.5: Error Handling Enhancement from the implementation plan.
Copilot AI review requested due to automatic review settings November 19, 2025 04:54
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @otomatty, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

このプルリクエストは、アプリケーションのエラーハンドリングシステムを大幅に強化することを目的としています。統一されたエラータイプ、構造化されたロギング、国際化されたエラーメッセージ、そして改善されたエラーバウンダリーを導入することで、エラーの特定、デバッグ、およびユーザーへのフィードバックがより効率的かつユーザーフレンドリーになります。これにより、アプリケーション全体の堅牢性と保守性が向上します。

Highlights

  • 統一エラータイプとクラス: アプリケーション全体で利用する統一的なエラータイプと、サーバーサイド・クライアントサイドそれぞれに特化したエラークラスを導入しました。
  • 構造化エラーロギング: 開発環境と本番環境で異なる詳細度でエラーを記録する、構造化されたエラーロギング機能を実装しました。
  • Server Actions用エラーハンドリングユーティリティ: Server Actionsにおけるエラー処理を一元化するためのラッパー関数(handleServerAction, handleDatabaseAction)を提供します。
  • エラーメッセージの国際化 (i18n): エラーメッセージを日本語と英語で提供し、i18nユーティリティを通じて多言語対応を強化しました。
  • エラーバウンダリーの改善: app/error.tsxapp/global-error.tsx をi18n対応させ、開発環境での詳細情報表示やクライアントサイドでのエラーログ記録を改善しました。
  • Server Actionsへの統一適用: 既存のすべてのServer Actionsに新しいエラーハンドリングロジックを適用し、エラー処理の一貫性を確保しました。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

このプルリクエストは、アプリケーション全体のエラーハンドリングを統一し、強化するための素晴らしい改善ですね。統一的なエラー型、構造化ロギング、i18n対応、エラーハンドリングのユーティリティ導入など、非常に広範囲にわたる変更が首尾一貫して実装されています。

特に、handleServerActionhandleDatabaseActionといったラッパー関数によって、各Server Actionのコードが非常にクリーンになり、エラーハンドリングのロジックが集約された点は高く評価できます。

いくつかの改善点を提案させていただきました。

  • ClientErrorおよびServerErrorクラスにおけるlevelプロパティの型安全性の向上
  • handleServerAction内での、より堅牢なエラー判定方法の検討
  • logger.tsにおける重複コードの削除

これらの点を修正することで、さらに保守性が高く、堅牢なエラーハンドリング機構になるかと思います。素晴らしい仕事をありがとうございます!

Comment thread lib/errors/logger.ts Outdated
Comment thread lib/errors/client.ts Outdated
Comment thread lib/errors/client.ts Outdated
Comment thread lib/errors/handler.ts Outdated
Comment thread lib/errors/server.ts Outdated
Comment thread lib/errors/server.ts Outdated
Comment thread lib/errors/server.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements comprehensive error handling enhancements including unified error types, structured logging, i18n-supported error messages, and improved error boundaries. The implementation focuses on providing consistent error handling across server actions and client components.

  • Introduces a centralized error handling system with typed error classes for both server and client
  • Implements structured logging with environment-specific output (detailed for development, sanitized for production)
  • Adds internationalization support for error messages in Japanese and English

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
lib/errors/types.ts Defines core error types, interfaces, and utility functions for error handling
lib/errors/server.ts Server-side error classes (DatabaseError, ValidationError, etc.)
lib/errors/client.ts Client-side error classes (NetworkError)
lib/errors/logger.ts Structured logging functionality with environment-aware output
lib/errors/handler.ts Error handling wrappers for server actions
lib/errors/i18n.ts i18n utilities for error message translation
lib/errors/index.ts Centralized exports for error handling module
public/locales/ja/errors.json Japanese error message translations
public/locales/en/errors.json English error message translations
lib/i18n/i18n.settings.ts Adds 'errors' namespace to i18n configuration
app/error.tsx Enhanced error page with i18n, logging, and development info display
app/global-error.tsx Enhanced global error page with i18n, logging, and development info display
hooks/useErrorHandler.ts Updated hook to use new error system with logging and i18n
actions/*.ts All server actions wrapped with unified error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/errors/server.ts Outdated
Comment thread lib/errors/server.ts Outdated
Comment thread lib/errors/server.ts Outdated
Comment thread lib/errors/client.ts Outdated
Comment thread lib/errors/client.ts Outdated
Comment thread lib/errors/handler.ts
Comment thread lib/errors/handler.ts
Comment on lines +61 to +66
if (
error instanceof Error &&
(error.message.includes('validation') ||
error.message.includes('invalid') ||
error.message.includes('required'))
) {
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

Error detection based on message string matching is fragile and language-dependent. Consider using error codes, error types, or instanceof checks for more reliable error classification.

Copilot uses AI. Check for mistakes.
Comment thread lib/errors/handler.ts
Comment thread lib/errors/handler.ts
Comment thread lib/errors/handler.ts
- Remove duplicate isAppError and toAppError functions from logger.ts
- Change level property type from string to ErrorLevel in ServerError and ClientError
- Remove unnecessary 'as any' type assertions
- Improve error detection in handleServerAction to use instanceof checks and better-sqlite3 error codes
- Add better-sqlite3 SqliteError detection based on error code and name properties
@otomatty
Copy link
Copy Markdown
Owner Author

レビュー対応完了

コードレビューで指摘いただいた点について、以下の対応を行いました。

対応内容

1. 重複コードの削除(高優先度)

  • ファイル: lib/errors/logger.ts
  • 対応: isAppErrortoAppError関数の重複定義を削除し、lib/errors/types.tsからインポートするように変更しました。
  • 効果: コードの重複を排除し、保守性が向上しました。

2. 型安全性の向上(中優先度)

  • ファイル: lib/errors/server.ts, lib/errors/client.ts
  • 対応:
    • levelプロパティの型をstringからErrorLevelに変更
    • コンストラクタのlevelオプションもErrorLevel型に変更
    • toAppError()メソッドのas anyキャストを削除
  • 効果: 型の整合性が保たれ、コンパイル時に不正な値の代入を検出できるようになりました。

3. エラー判定の改善(中優先度)

  • ファイル: lib/errors/handler.ts
  • 対応:
    • better-sqlite3のSqliteErrorを検出するロジックを追加(codeプロパティがSQLITE_で始まる、またはnameSqliteError
    • instanceofチェックを優先的に使用(ValidationErrorNotFoundError
    • メッセージベースの判定はフォールバックとして維持
  • 効果: エラーメッセージの文字列に依存しない、より堅牢なエラー判定が可能になりました。

変更ファイル

  • lib/errors/logger.ts - 重複関数の削除、インポートの追加
  • lib/errors/server.ts - 型定義の修正、as anyキャストの削除
  • lib/errors/client.ts - 型定義の修正、as anyキャストの削除
  • lib/errors/handler.ts - エラー判定ロジックの改善

テスト

  • リンターエラーなし
  • 型チェックエラーなし
  • すべての変更が適切に動作することを確認

ご指摘いただいた点について、すべて対応いたしました。ご確認のほどよろしくお願いいたします。

@otomatty otomatty merged commit 8aa13bd into develop Nov 19, 2025
1 check passed
@otomatty otomatty deleted the feature/error-handling-enhancement branch November 19, 2025 07:03
otomatty added a commit that referenced this pull request Nov 19, 2025
…ment

- Mark Phase 6.5 as completed
- Add implementation completion date (2025-11-19)
- Add detailed implementation content
- Add GitHub PR link (#13)
- Update completed tasks section
- Update priority section
- Update implementation schedule
- Add error handling module references
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.

2 participants