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

Add option to disable panic recovery in message processing #4136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

APshenkin
Copy link
Contributor

@APshenkin APshenkin commented Mar 13, 2025

Description

Allow handle panics manually by providing DisablePanicRecovery option

Fixes #4135

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a configuration option that lets users toggle the application's automatic error recovery behavior, offering greater flexibility in how critical errors are managed.
  • Documentation

    • Updated the user guide to detail the new DisablePanicRecovery option for error handling.
    • Added a new entry in the changelog to document the DisablePanicRecovery feature, including credit to the contributor.

Copy link
Contributor

coderabbitai bot commented Mar 13, 2025

Walkthrough

The changes introduce a new boolean option to control panic recovery during message processing. Specifically, the dispatcher’s constructor now accepts an additional parameter (disablePanicRecovery) that can be configured from the application options. Modifications have been made in both development and production app initialization, within the dispatcher’s construction and processing logic, and in the configuration options and documentation.

Changes

File(s) Change Summary
v2/internal/app/app_dev.go
v2/internal/app/app_production.go
Updated calls to dispatcher.NewDispatcher to include the new DisablePanicRecovery parameter in the argument list.
v2/internal/frontend/dispatcher/dispatcher.go Updated the NewDispatcher signature to accept the disablePanicRecovery flag; added the field to the Dispatcher struct and modified panic handling logic.
v2/pkg/options/options.go Added a new boolean field DisablePanicRecovery to the App struct.
website/docs/reference/options.mdx Documented the new DisablePanicRecovery configuration option in the options reference.
website/src/pages/changelog.mdx Added an entry for the new DisablePanicRecovery feature in the changelog.

Assessment against linked issues

Objective Addressed Explanation
Allow to disable panic recovery (#[4135])

Suggested reviewers

  • leaanthony

Poem

Hoppin’ through the code, I skip with glee,
New flags in the dispatch guide set us free.
Panic steps aside when recovery is off,
My carrot dreams abound—no need to scoff.
From the burrow of code, cheers echo so bright!
🥕🐰 Coding is fun under moonlit byte light.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ef73a75 and 125c4ab.

📒 Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/pages/changelog.mdx

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

🧹 Nitpick comments (2)
v2/internal/frontend/dispatcher/dispatcher.go (2)

35-49: Consider adding error logging for the non-recovery case.

The implementation conditionally wraps the panic recovery logic based on the disablePanicRecovery flag, which is good. However, when panic recovery is disabled, the error logging at lines 45-47 will also be skipped since it's inside the defer block.

Consider adding error logging outside the conditional block to ensure errors are still logged even when panic recovery is disabled. This would help with debugging and monitoring in both modes.

func (d *Dispatcher) ProcessMessage(message string, sender frontend.Frontend) (_ string, err error) {
	if !d.disablePanicRecovery {
		defer func() {
			if e := recover(); e != nil {
				if errPanic, ok := e.(error); ok {
					err = errPanic
				} else {
					err = fmt.Errorf("%v", e)
				}
			}
			if err != nil {
				d.log.Error("process message error: %s -> %s", message, err)
			}
		}()
	} else {
+		// Still log errors when panic recovery is disabled
+		defer func() {
+			if err != nil {
+				d.log.Error("process message error: %s -> %s", message, err)
+			}
+		}()
	}

35-49: Add documentation to explain the disablePanicRecovery behavior.

The code would benefit from a comment explaining the purpose and behavior of the disablePanicRecovery flag. This would help future maintainers understand the intended behavior and the trade-offs involved in enabling/disabling panic recovery.

func (d *Dispatcher) ProcessMessage(message string, sender frontend.Frontend) (_ string, err error) {
+	// If disablePanicRecovery is false (default), we recover from panics during message processing
+	// and convert them to errors. If true, panics will propagate up the call stack, which can be
+	// useful for debugging or custom panic handling at a higher level.
	if !d.disablePanicRecovery {
		defer func() {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6a3ba3d and e910015.

📒 Files selected for processing (5)
  • v2/internal/app/app_dev.go (1 hunks)
  • v2/internal/app/app_production.go (1 hunks)
  • v2/internal/frontend/dispatcher/dispatcher.go (1 hunks)
  • v2/pkg/options/options.go (1 hunks)
  • website/docs/reference/options.mdx (1 hunks)
🔇 Additional comments (7)
v2/pkg/options/options.go (1)

101-103: New configuration option looks good!

The new DisablePanicRecovery field with its descriptive comment clearly indicates its purpose of controlling panic recovery in message processing. This is a useful option for developers who want to handle panics themselves.

website/docs/reference/options.mdx (1)

490-496: Documentation is clear and well-structured.

The documentation for the new DisablePanicRecovery option is thorough, explaining both the default behavior (automatic recovery and logging) and what happens when enabled (no automatic recovery). This provides users with a clear understanding of how to use this feature.

v2/internal/app/app_dev.go (1)

215-215: Correctly passing the new option to the dispatcher.

The DisablePanicRecovery option is properly passed to the dispatcher constructor, allowing the development environment to respect this configuration option.

v2/internal/app/app_production.go (1)

85-85: Consistently implemented in production environment.

The option is properly passed to the dispatcher in the production environment as well, ensuring consistent behavior across both development and production builds.

v2/internal/frontend/dispatcher/dispatcher.go (3)

13-21: Clean implementation of the disablePanicRecovery field.

The addition of the disablePanicRecovery boolean field to the Dispatcher struct is clean and well-aligned with the PR objective to provide an option for disabling panic recovery during message processing.


23-33: Constructor properly accepts and initializes the new parameter.

The updated NewDispatcher function correctly accepts the new parameter and initializes it in the struct. This change is consistent with the API modification mentioned in the PR summary.


35-49:

❓ Verification inconclusive

Verify panics propagate as expected when recovery is disabled.

When disablePanicRecovery is set to true, panics will no longer be caught in this function. Make sure that:

  1. The behavior is documented in the user-facing documentation
  2. Higher-level code is prepared to handle these panics if necessary
  3. The application has appropriate crash reporting for unexpected panics

This behavior change could impact application stability if not properly understood by users.


🏁 Script executed:

#!/bin/bash
# Look for any existing panic handlers in higher-level code
echo "Searching for panic handling in the codebase..."
rg -i "recover\(\)" --type go

Length of output: 215


Action Required: Confirm Documentation and Higher-Level Panic Handling

The current implementation in v2/internal/frontend/dispatcher/dispatcher.go correctly bypasses the deferred recovery block when disablePanicRecovery is set to true, allowing panics to propagate. However, please ensure that:

  • The user-facing documentation clearly explains that panics will not be recovered when this flag is enabled.
  • All higher-level code is reviewed and adequately prepared to handle any propagated panics.
  • Appropriate crash reporting mechanisms are in place to capture unexpected panics.

Our grep search confirmed that the sole use of recover() in the codebase is within this file. Please verify that no additional panic handlers exist that might interfere with this behavior and that any changes are properly communicated in the documentation.

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

🧹 Nitpick comments (1)
website/src/pages/changelog.mdx (1)

22-22: Improve clarity and consistency of the changelog entry.

The current entry "- Added DisablePanicRecovery option to allow handle panics manually ..." would be clearer if rephrased and its PR reference formatted consistently. Consider revising it as follows:

- - Added `DisablePanicRecovery` option to allow handle panics manually [#https://github.com/wailsapp/wails/pull/4136](https://github.com/wailsapp/wails/pull/4136) by [@APshenkin](https://github.com/APshenkin)
+ - Added `DisablePanicRecovery` option to allow manual handling of panics [#4136](https://github.com/wailsapp/wails/pull/4136) by [@APshenkin](https://github.com/APshenkin)

This change improves grammatical clarity and standardizes the PR reference format.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e910015 and 2478926.

📒 Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)

Copy link

sonarqubecloud bot commented Apr 1, 2025

@APshenkin
Copy link
Contributor Author

Hi @leaanthony

Anything that I can do so that it will be merged?

Kind regards,
Andrei

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.10.1 Allow to disable panic recovery
1 participant