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

Handling custom block initialization exceptions #1893

Open
Neutrino-Sunset opened this issue Jun 27, 2022 · 3 comments
Open

Handling custom block initialization exceptions #1893

Neutrino-Sunset opened this issue Jun 27, 2022 · 3 comments
Labels

Comments

@Neutrino-Sunset
Copy link

If a custom block throws an exception on initialization, the exception appears to completely bypass any middleware exception handling.

E.g. given this custom block

   [BlockType(Name = "Events", Category = "Content", Icon = "fas fa-calendar-alt", Component = "events-block")]
   public class CustomBlock : Block
   {
      public void Init()
      {
         throw new Exception("Event block exception");
      }
   }

Add this block to a page and then loading the page.

In Development mode the developer exception page is not displayed.

In Production mode UseExceptionHandler("/Error") does not take effect.

In both cases a plain 500 status code is returned resulting in the browser default error page, which is not what we want.

Does anyone know why this should be happening or what we should do to reinstate the behaviour of the exception handling middleware?

@tidyui
Copy link
Member

tidyui commented Jun 27, 2022

Define what you mean by “loading a page”. Are you using Razor Pages or MVC? I’ve looked at the PageService and there shouldn’t be any try/catches on service level for initialization errors.

@Neutrino-Sunset
Copy link
Author

I'm using Razor pages. If you take the Piranha Razor pages template app and add that custom block to a page, then when you navigate to the page containing the block (not in the manager) that's when it returns an error that appears to bypass any exception/error handling middleware.

@Neutrino-Sunset
Copy link
Author

The way I'm handling this is to catch all exceptions from custom block constructors, this is a decent approach as it's then possible to display the error message in the display of the block itself rather than crashing the services, but for those exceptions that are missed for whatever reason it would be much better if the standard processing functioned normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants