MasoniteFramework / exceptionite

A Python Exception Library. Designed to make handling and displaying exceptions a cinch.
MIT License
124 stars 4 forks source link

More documentation for Adding Context with Masonite #66

Open tpow opened 1 year ago

tpow commented 1 year ago

The exceptionite readme documentation is quite helpful. Thanks!

However, I am using Masonite (v4) and it took me a bit to figure out a reasonable way to add an additional block to the context tab. The Adding Context section shows a handler, but I wasn't sure of the best way to get it in the Masonite context.

I ended up creating a new provider:

python craft provider ExceptioniteContextProvider

I then updated it to include the new block (shown here using the sample from the readme):

import sys

from exceptionite import Block                                                   
from masonite.providers import Provider

class ExceptioniteContextProvider(Provider):                                         
    def __init__(self, application):
        self.application = application

    def register(self):                                                          
        handler = self.application.make("exception_handler").get_driver("exceptionite")
        if handler:
            handler.renderer("web").tab("context").add_blocks(SystemVarsBlock)

    def boot(self):
        pass

class SystemVarsBlock(Block):
    id = "system_vars"
    name = "System Variables"
    icon = "LightBulbIcon"

    def build(self):
        return {
           "sys argv": sys.argv
        }

I then added it to Masonite's config/providers.py by updating the file:

...
from app.providers import ExceptioniteContextProvider

PROVIDERS = [
    ...
    ExceptioniteContextProvider,
]

This works, but I'd love to know if there's a better approach. Do I need to check for debug mode or otherwise make sure that exceptionite is being used? Ideally this could be deployed in a production environment without needing changes to disable it.

Should something like this be added to the documentation?

Thanks!