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

ErrorBoundary support for multiple exceptions #38905

Open
thirstyape opened this issue Dec 8, 2021 · 18 comments
Open

ErrorBoundary support for multiple exceptions #38905

thirstyape opened this issue Dec 8, 2021 · 18 comments
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-error-boundary
Milestone

Comments

@thirstyape
Copy link

Am I using this incorrectly? I implemented as per Documentation in MainLayout.razor with the slight change that in my <ErrorContent> section I added a button that triggers errorBoundary?.Recover();.

My test involved throwing a generic exception with a message from a child component in protected override void OnInitialized(). The result was that instead of displaying the content of @Body or the ErrorContent, there was nothing. Upon opening the browser inspector I had an empty <main></main>.

I also tried creating a custom class that implemented ErrorBoundary, but this did not help either.

Originally posted by @thirstyape in #30874 (comment)

@TanayParikh TanayParikh added area-blazor Includes: Blazor, Razor Components feature-blazor-error-boundary labels Dec 8, 2021
@TanayParikh
Copy link
Contributor

Does it work as expected if you throw the exception in OnParametersSet instead of OnInitialized? That's the event used in the docs and occurs after OnInitialized, so I wonder if this is an event ordering issue.

@TanayParikh TanayParikh added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Dec 8, 2021
@ghost
Copy link

ghost commented Dec 8, 2021

Hi @thirstyape. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@thirstyape
Copy link
Author

Yes, it occurred in OnParametersSet as well. That was actually the first time I noticed this. I tested a basic scenario on Index.razor in its OnIntialized event and that worked as expected. Then I changed a different component from using OnIntialized to OnParametersSet which threw an exception (it should have). This caused the issue where there was nothing in the <main>. I then modified the event code to throw a generic exception instead of its normal actions, which caused the issue regardless of which event I used.

For reference, the component that is seeing issue is a Tab within a TabBar. A merge of the component tree has code similar to the following, I can provide more detailed samples if anything could use further investigation:

<MainLayout>
  <ErrorBoundary>
    <ChildContent>
       <UserPage>
          <TabBar>
            <Tab>
            </Tab>
            <Tab>
            </Tab>
          </TabBar>
       </UserPage>
    </ChildContent>
    <ErrorContent>
       <button @onclick="Reset">Reset Error</button>
    </ErrorContent>
  <ErrorBoundary>
</MainLayout>

The TabBar has <CascadingValue Value="this"> that contains the ChildContent for the Tab items. The Tab items add themselves to a collection in the TabBar in the event call.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Dec 8, 2021
@TanayParikh
Copy link
Contributor

Could you please provide a minimal (using the base Blazor template with minimal additions) public github repro project to allow us to investigate further?

@TanayParikh TanayParikh added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Dec 8, 2021
@ghost
Copy link

ghost commented Dec 8, 2021

Hi @thirstyape. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@thirstyape
Copy link
Author

Done, here is the repository.

Changes to default template:

  • Add TabBar.razor and TabBar.razor.cs
  • Add Tab.razor
  • Update MainLayout.razor to include ErrorBoundary
  • Update Index.razor to include TabBar
  • Remove default error notice from index.html

Steps to reproduce:

  1. Go into Tab.razor and change the OnInitialized to OnParametersSet
  2. Run the app
  3. Click the "Click me" text

This will produce some exceptions and the <article> will be empty. Interestingly, navigating to another component will correct the behavior and the Failed message appears.

Unexpected behavior:
I am not sure why, but when I started the app the Tab items did not appear. I needed to add the "Click me" tab directly in TabBar.razor and then click it to get the rest of the tabs to appear. After that they work as expected.

This is making me think the TabBar or Tab components may not be structured correctly.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Dec 9, 2021
@TanayParikh
Copy link
Contributor

Thanks @thirstyape for the repro. I took a look and I believe it may be because in your example multiple exceptions are being thrown. If we update your example to just throw a single exception, things work as expected (Failed is shown).

diff --git a/BlazorApp1/Shared/Tab.razor b/BlazorApp1/Shared/Tab.razor
index f59c9e1..475e711 100644
--- a/BlazorApp1/Shared/Tab.razor
+++ b/BlazorApp1/Shared/Tab.razor
@@ -16,8 +16,8 @@
     [CascadingParameter]
     private TabBar Parent { get; set; }
 
-    protected override void OnInitialized()
-    //protected override void OnParametersSet() // Changing to this will cause the issue
+    // protected override void OnInitialized()^M
+    protected override void OnParametersSet() // Changing to this will cause the issue^M
     {
         Parent.Tabs.Add(Name, Icon);
     }
diff --git a/BlazorApp1/Shared/TabBar.razor.cs b/BlazorApp1/Shared/TabBar.razor.cs
index 24a6221..576ae92 100644
--- a/BlazorApp1/Shared/TabBar.razor.cs
+++ b/BlazorApp1/Shared/TabBar.razor.cs
@@ -39,8 +39,7 @@ public partial class TabBar
 
     private void OnTabBarChanged(string tab)
     {
-        Active = tab;
-        StateHasChanged();
+               throw new Exception("Yay for exceptions");^M
     }

This is making me think the TabBar or Tab components may not be structured correctly.

I believe this may be the case as well, I skimmed your code, but didn't immediately see what you were using to trigger the exception. My interpretation is the OnParametersSet is being triggered multiple times and that's causing a duplicate key to be added to the Parent.Tabs leading to the (multiple) exceptions. I'd recommend reviewing your code in that case. If you still believe this to be a framework bug, we'll need an even simpler repro app that doesn't require understanding the heuristics of TabBar, Tab, etc.

may be because in your example multiple exceptions are being thrown

@SteveSandersonMS are there any restrictions with respect to ErrorBoundary's and multiple exceptions?

@TanayParikh TanayParikh added ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Dec 9, 2021
@ghost ghost added the Status: Resolved label Dec 9, 2021
@thirstyape
Copy link
Author

Hi @TanayParikh, thank you for reviewing this.

Yes, as the <Tab> component has multiple instances, there will be multiple exceptions. If that is not currently a supported way to use <ErrorBoundary> we can close this issue. Of course, that would be nice to see eventually :)

@TanayParikh
Copy link
Contributor

TanayParikh commented Dec 9, 2021

I'll leave this open to confirm if there are any restrictions with respect to ErrorBoundary's and multiple exceptions.

@TanayParikh TanayParikh changed the title ErrorBoundary not working as expected ErrorBoundary support for multiple exceptions Dec 9, 2021
@TanayParikh TanayParikh removed ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved labels Dec 9, 2021
@TanayParikh TanayParikh added this to the Backlog milestone Dec 9, 2021
@ghost
Copy link

ghost commented Dec 9, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@TanayParikh TanayParikh modified the milestones: Backlog, Discussions Dec 9, 2021
@thirstyape
Copy link
Author

@TanayParikh I did some further testing today and I believe that we can close this out. I was able to use the sample project and get everything to work as expected as long as there was a single exception.

I pushed my changes to the test. With these updates, the ErrorBoundary now works as expected and can be re-used as many times as needed. That is, it will not stop working after the first time. Simply clicking the reset button I added will allow the process to repeat.

I think we can reasonably conclude that the multiple exceptions was the cause and is not currently a supported scenario.

@TanayParikh
Copy link
Contributor

Thanks @thirstyape, let's keep this issue open to track potentially adding support for multiple exceptions in the future.

@TanayParikh TanayParikh reopened this Dec 14, 2021
@ghost
Copy link

ghost commented Feb 12, 2022

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

@ghost ghost closed this as completed Feb 12, 2022
@TanayParikh
Copy link
Contributor

@SteveSandersonMS would you like to keep this open?

@SteveSandersonMS
Copy link
Member

Sure, let's reopen and keep on backlog.

@ghost
Copy link

ghost commented Feb 15, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@SteveSandersonMS SteveSandersonMS added enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed question labels Feb 15, 2022
@eduard-tapkey
Copy link

Are there any updates on this topic? One year later it seems multiple exceptions at once are not supported by ErrorBoundary. The ErrorContent won't render.

@zerox981
Copy link

zerox981 commented Sep 3, 2024

This bug is making the ErrorBoundary useless for real world scenarios. As soon as we have more than 1 component failing (in OnInitialized(Async), OnParameterSet(Async), nothing gets rendered on the screen (the render code is executed, but there is no output).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-error-boundary
Projects
None yet
Development

No branches or pull requests

6 participants