MudBlazor / Templates

Ready to use Blazor Templates in different styles and layout with all the basic setup already done for MudBlazor.
MIT License
745 stars 165 forks source link

MudBlazor template is missing unhandled exceptions div #466

Closed d00lar closed 5 months ago

d00lar commented 6 months ago

Bug type

Component, Other

Component name

MainLayout

What happened?

in default MudBlazor serwerside template in routes.razor / old index.html

You guys are missing

<div id="blazor-error-ui"> <span style="color:black">An unhandled error has occurred.</span> <a href="" class="reload">Reload</a> <a class="dismiss">🗙</a> </div>

without this when there is an unhandled expeption

for example if in famus 'counter' component page we change from

private void IncrementCount()
{
    currentCount++;
}

to

private async Task IncrementCount()
{
      currentCount++;
      throw new Exception("test");
}

then onclick there is no exception throwed in VS and app just freeze.

BE AWARE IN TRY MUDBLAZOR LINK everything is ok in default New Project / MudBlazor template NO.

Expected behavior

in defualt template error handling 'down bar' should be also implemented

Reproduction link

https://try.mudblazor.com/snippet/mEGIaTGkGgKtdJXD https://stackoverflow.com/questions/78493661/blazor-serverside-why-is-exception-not-thrown-when-in-task-how-to-avoid-this

Reproduction steps

  1. new serverside project from mudblazor templates
  2. change counter page code to as i wrote above
  3. vlick on counter btn. ...

Relevant log output

No response

Version (bug)

6.19

Version (working)

No response

What browsers are you seeing the problem on?

Chrome

On which operating systems are you experiencing the issue?

Windows

Pull Request

Code of Conduct

MBNSoftware commented 6 months ago

Hello,

Could this "help" ?

https://medium.com/@alexandre.malavasi/why-exceptions-in-async-methods-are-dangerous-in-c-fda7d382b0ff

To summarize, it's mainly because the Task is not (may not be) awaited. Which is potentially understandable if the original method was not a task : the calls to it were not "awaited".

So I would not qualify this as a bug but rather as a bad programming practice (no offence to you, of course).

Regards, Christophe

d00lar commented 6 months ago

Yes i known all that but best practise is best practise and life is life / sometimes someone can forget something but still in default .net template there is some 'bar' at the bottom of page with reload btn as You probably known so same thing im expecting in mudblazor template? in .net6 template of mudblazor WebAssembly it was but in .net 8 template for 'server side' project there is not - this DIV is missing with this as i wrote

An unhandled error has occurred. Reload 🗙

this is as expected - do You think it should not be there anymore? regards

MBNSoftware commented 6 months ago

To be honest, as I feel it's a "bad programming practice", I would not even try to solve this. It would add mess where there's already enough, I think.

Don't get me wrong, though, I understand your need to handle such exception in a task. But, as many sources seem to agree, the correct way to handle it properly is to await the call. Period. I'm not skilled enough to go against that, hence my advice to (try to) stay with good practice. Again, no offence but pure common sense or pragmatism,

Regards, Christophe

d00lar commented 6 months ago

so You guys think that default blazor option for handling unhandled exceptions - 'Down bar showing that some error occured and You can try reload' is not needed anymore? but it was needes sometimes ago..? in mudblazor older / webassembly template? from witch version this concept is abbanden?

Anu6is commented 6 months ago

I think you guys are discussing two different things. @MBNSoftware is addressing how to address the specific exception scenario you gave as an example. While @d00lar is simply saying that the basic unhandled exception catch all logic is missing from the template. The issue raised has nothing to do with awaiting a task or not but what happens when an unhandled exception occurs.

The issue was also brought up on the template repo https://github.com/MudBlazor/Templates/issues/451

d00lar commented 6 months ago

exacly - it is just example nothing more. also it just 'freaze app' when this div is missing so if some unaware developer will hit this kind of error - he can wait even hour or two waiting for task to compleat seeing no error or no sign of something bad happened.

jperson2000 commented 6 months ago

Hi everyone, as part of upgrading templates for the upcoming MudBlazor 7.0.0 release, I rebuilt templates from scratch and the error <div> is there. You can find the change in this PR: https://github.com/MudBlazor/Templates/pull/465

ScarletKuro commented 5 months ago

Transferred the issue to MudBlazor/Templates repo