Skip to main content

Beautiful debugging page for starlite apps.

Project description

##############

NOTE: this is a fork of https://github.com/alex-oleshkevich/starception

All rights to him and the contributors for that repo.

This fork exists to implement starception for starlite: https://github.com/starlite-api/starlite.

Starlite left starlette since version [1.39.0] for there own implementations.

Therefore the orginal repo doens't work anymore

Seeing starception was originally built for starlette backed frameworks. So a fork was needed to make this work with starlite

Note2 : I will keep the fork in sync with the main repo except for the starlette stuff.

##############

Starception-starlite

Beautiful exception page for Starlette and FastAPI apps.

PyPI GitHub Workflow Status GitHub Libraries.io dependency status for latest release PyPI - Downloads GitHub Release Date

Installation

Install starlite-starception using PIP or poetry:

pip install starlite_starception
# or
poetry add starlite_starception

With syntax highlight support

If you want to colorize code snippets, install pygments library.

pip install starlite_starception[pygments]
# or
poetry add starlite_starception -E pygments

Screenshot

image

Dark theme

Features

  • secrets masking
  • solution hints
  • code snippets
  • display request info: query, body, headers, cookies
  • session contents
  • request and app state
  • platform information
  • environment variables
  • syntax highlight
  • open paths in editor (vscode only)
  • exception chains
  • dark theme

The middleware will automatically mask any value which key contains key, secret, token, password.

Quick start

See example application in examples/ directory of this repository.

Usage

Starception will work only in debug mode so don't forget to set debug=True for local development.

Monkey patching Starlette

To replace built-in debug exception handler call install_error_handler before you create Starlette instance.

Currently, this is a recommended approach.

from starlite_starception import install_error_handler
from starlite import Starlite, get


@get("/")
def view() -> None:
    raise TypeError('Oops')


install_error_handler()
app = Starlite(route_handlers=[view])

Using middleware

To render a beautiful exception page you need to install a StarceptionMiddleware middleware to your application.

Note, to catch as many exceptions as possible the middleware has to be the first one in the stack.

import typing

from starlite import Starlite

from starlite_starception import StarceptionMiddleware


async def index_view() -> None:
    raise Exception('Oops, something really went wrong...')


app = Starlite(
    debug=True,
    route_handlers=[index_view],
    middleware=[
        StarceptionMiddleware,
        # other middleware go here
    ]
)

Solution hints

If exception class has solution attribute then its content will be used as a solution hint.

class WithHintError(Exception):
    solution = (
        'The connection to the database cannot be established. '
        'Either the database server is down or connection credentials are invalid.'
    )

image

Opening files in editor

Set your current editor to open paths in your editor/IDE.

from starlite_starception import set_editor

set_editor('vscode')

image

Note, currently only VSCode supported. If you know how to integrate other editors - please PR

Registering link templates

If your editor is not supported, you can add it by calling add_link_template and then selecting it with set_editor.

from starlite_starception import set_editor, add_link_template

add_link_template('vscode', 'vscode://file/{path}:{lineno}')
set_editor('vscode')

Credentials

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starlite_starception-1.0.1.1.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

starlite_starception-1.0.1.1-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file starlite_starception-1.0.1.1.tar.gz.

File metadata

  • Download URL: starlite_starception-1.0.1.1.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/6.0.6-76060006-generic

File hashes

Hashes for starlite_starception-1.0.1.1.tar.gz
Algorithm Hash digest
SHA256 eec06b50eb65d5f1f26485a217056a9063d97f69574a0c63211e8dfa3c499fb4
MD5 44caf94e760c55915ee80d5ec06fc49e
BLAKE2b-256 b686673b9ee317199e0b440df1238a077cc160d765b4b09f693db9800c496f79

See more details on using hashes here.

File details

Details for the file starlite_starception-1.0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for starlite_starception-1.0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de0d0a9729c987d757c547311bfeded2f914fb5a96effe1ad492e492a69495c3
MD5 ad5db4d3757c4783291001b2c96bc765
BLAKE2b-256 47ac47cc25ed185289fd04180edb5fc0472bf9e8ea0ff6570e73c1cf399f1d73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page