dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.37k stars 9.99k forks source link

Blazor - Error Boundary not triggered inside of EditForm Component #40649

Closed casper7526 closed 2 years ago

casper7526 commented 2 years ago

If you have the following:

<ErrorBoundary>
<ChildContent>
@Body
</ChildContent>
</ErrorBounday>

You expect that any exceptions within your pages will flow upwards and hit the errorbounday handling code. For 99% of things I have tried this holds true.

HOWEVER

If you trigger an exception while inside of Editforms methods (onSubmit,OnValidSubmit) you will bypass the errorboundary handler and be shown the default circuit error at the bottom of the screen.

<EditForm OnValidSubmit="OnSubmit"> .....

public void OnSubmit(){
throw new Exception("Error");
}

This seems to bypass the intended function of ErrorBoundary and while I am explaining it in a global manner it would still fail if it was done within a page itself.

ghost commented 2 years ago

Thanks for contacting us. We're moving this issue to the .NET 7 Planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

jimmytricks commented 2 years ago

I ran into this issue too, so a +1 on being able to do this, as it's intuitive in my opinion that you should be able to wrap the EditForm with an ErrorBoundary and expect it to work

gbthakkar commented 2 years ago

Hi, I too ran into this today. ErrorBoundry works in normal case work but not when EditForm trigger the error like given by @casper7526 . But then Blazor being the SPA, I have situation where has the pages are having EditForm on it. (I believe, will be the case for most developer). So by the time you consider this as valid case, kindly provide some alternative to cover this situation. ... try-catch is one thing which is obvious on our side. But looking for something like ErrorBoundry. Thanks

casper7526 commented 2 years ago

I'm closing this issue, I was able to solve it on my own.

I was using a public async void as a method and Blazor is unable to await that (which is needed for boundaries).

Changing the method to be public async Task allows boundaries to work inside an EditForm