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

一部のエラーメッセージの内容が表示されない問題を改善 #1083

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

sunfish-shogi
Copy link
Owner

@sunfish-shogi sunfish-shogi commented Jan 23, 2025

説明 / Description

#1051

メインプロセスからレンダラープロセスへ Error を伝播する部分の実装を改善する。

チェックリスト / Checklist

  • MUST
    • npm test passed
    • npm run lint was applied without warnings
    • changes of /docs/webapp not included (except release branch)
    • console.log not included (except script file)
  • MUST for Outside Contributor
  • RECOMMENDED (it depends on what you change)
    • unit test added/updated
    • i18n

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling mechanism to better process and report errors, especially for complex error types like AggregateError.
    • Simplified error communication by converting error objects to string representations.
  • Refactor

    • Modified error reporting across multiple components to standardize error message transmission.
    • Updated error callback signatures to use string-based error reporting.

These changes improve error handling and communication within the application, making error tracking and debugging more consistent.

@sunfish-shogi sunfish-shogi self-assigned this Jan 23, 2025
Copy link

coderabbitai bot commented Jan 23, 2025

Warning

Rate limit exceeded

@sunfish-shogi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between fcb194e and 5d4bf0f.

📒 Files selected for processing (6)
  • src/background/window/ipc.ts (1 hunks)
  • src/renderer/ipc/bridge.ts (1 hunks)
  • src/renderer/ipc/preload.ts (1 hunks)
  • src/renderer/ipc/setup.ts (1 hunks)
  • src/renderer/store/error.ts (1 hunks)
  • src/tests/renderer/store/error.spec.ts (1 hunks)

Walkthrough

The pull request introduces modifications to error handling across multiple files in the project. The primary change involves transforming how errors are processed and communicated between different components. The sendError function in the background process now supports handling AggregateError by recursively processing multiple errors. Simultaneously, error handling methods across renderer-related files have been updated to expect and process error information as strings instead of full Error objects.

Changes

File Change Summary
src/background/window/ipc.ts Enhanced sendError function to recursively handle AggregateError, processing multiple errors individually
src/renderer/ipc/bridge.ts, src/renderer/ipc/preload.ts, src/renderer/ipc/setup.ts Updated onSendError method signature to accept string instead of Error in all three files
src/renderer/store/error.ts Modified add method in ErrorStore to handle AggregateError by processing its individual errors

Possibly related PRs

Suggested labels

bug

Poem

🐰 Errors hop and bounce around,
From aggregate to string they're bound,
With recursive grace they now descend,
A rabbit's tale of code that mends,
Error handling, clean and sound! 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@sunfish-shogi sunfish-shogi changed the title Enhance the error propagation over IPC 一部のエラーメッセージの内容が表示されない問題を改善 Jan 23, 2025
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.58%. Comparing base (4b99ee3) to head (5d4bf0f).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1083   +/-   ##
=======================================
  Coverage   76.57%   76.58%           
=======================================
  Files         121      121           
  Lines       15644    15650    +6     
  Branches     2532     2536    +4     
=======================================
+ Hits        11979    11985    +6     
  Misses       3643     3643           
  Partials       22       22           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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

🧹 Nitpick comments (1)
src/background/window/ipc.ts (1)

942-948: LGTM! Enhanced error handling with AggregateError support.

The implementation correctly handles AggregateError by recursively processing each error in the aggregate. This is a good improvement that allows for better error propagation when multiple errors occur.

Consider adding a separator between multiple error messages to improve readability:

 if (e instanceof AggregateError) {
+  const separator = "\n---\n";
+  let isFirst = true;
   for (const error of e.errors) {
+    if (!isFirst) {
+      mainWindow.webContents.send(Renderer.SEND_ERROR, separator);
+    }
     sendError(error);
+    isFirst = false;
   }
   return;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b99ee3 and 7200601.

📒 Files selected for processing (4)
  • src/background/window/ipc.ts (1 hunks)
  • src/renderer/ipc/bridge.ts (1 hunks)
  • src/renderer/ipc/preload.ts (1 hunks)
  • src/renderer/ipc/setup.ts (1 hunks)
🔇 Additional comments (3)
src/renderer/ipc/bridge.ts (1)

15-15: LGTM! Updated error callback signature.

The change from Error to string type aligns with the main process's error handling, where errors are converted to messages before being sent over IPC.

src/renderer/ipc/setup.ts (1)

68-70: LGTM! Consistent error handling implementation.

The implementation correctly uses the error store to handle the string error messages received from the main process.

src/renderer/ipc/preload.ts (1)

26-29: LGTM! Consistent preload implementation.

The implementation correctly bridges the IPC error events to the renderer process, maintaining type safety with the updated string-based error handling.

Copy link

@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

🧹 Nitpick comments (2)
src/renderer/store/error.ts (2)

29-34: Consider adding recursion depth protection.

The recursive handling of AggregateError could potentially cause stack overflow with deeply nested errors.

Consider adding a depth limit:

-  add(e: unknown): void {
+  add(e: unknown, depth: number = 0): void {
+    if (depth > 100) { // arbitrary limit, adjust as needed
+      this.errorCounts["Maximum error depth exceeded"] = 
+        (this.errorCounts["Maximum error depth exceeded"] || 0) + 1;
+      return;
+    }
     if (e instanceof AggregateError) {
       for (const err of e.errors) {
-        this.add(err);
+        this.add(err, depth + 1);
       }
       return;
     }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 30-34: src/renderer/store/error.ts#L30-L34
Added lines #L30 - L34 were not covered by tests


35-35: Consider extracting error message cleanup logic.

The regex cleanup of error messages is hardcoded and specific. Consider making it more maintainable.

Consider extracting the cleanup logic:

+  private static readonly ERROR_PATTERNS = [
+    /Error invoking remote method '[^']*': Error: /,
+    // Add more patterns here as needed
+  ];
+
+  private cleanErrorMessage(message: string): string {
+    return ErrorStore.ERROR_PATTERNS.reduce(
+      (msg, pattern) => msg.replace(pattern, ""),
+      message
+    );
+  }
+
   add(e: unknown): void {
     if (e instanceof AggregateError) {
       for (const err of e.errors) {
         this.add(err);
       }
       return;
     }
     let message = e instanceof Error ? e.message || e.name : "" + e;
-    message = message.replace(/Error invoking remote method '[^']*': Error: /, "");
+    message = this.cleanErrorMessage(message);
     const count = this.errorCounts[message] || 0;
     this.errorCounts[message] = count + 1;
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7200601 and fcb194e.

📒 Files selected for processing (1)
  • src/renderer/store/error.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/renderer/store/error.ts

[warning] 30-34: src/renderer/store/error.ts#L30-L34
Added lines #L30 - L34 were not covered by tests

🔇 Additional comments (1)
src/renderer/store/error.ts (1)

29-34: Add test coverage for AggregateError handling.

The new AggregateError handling logic is not covered by tests. This is critical functionality that should be thoroughly tested.

Would you like me to help generate test cases? Here are the scenarios we should cover:

  1. Single AggregateError with multiple basic errors
  2. Nested AggregateErrors
  3. Empty AggregateError
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 30-34: src/renderer/store/error.ts#L30-L34
Added lines #L30 - L34 were not covered by tests

@sunfish-shogi sunfish-shogi merged commit 7d3b708 into main Jan 23, 2025
5 checks passed
@sunfish-shogi sunfish-shogi deleted the update-senderror branch January 23, 2025 16:50
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.

1 participant