Skip to main content

A simple Python package for explicit errors

Project description

Python Error Boundary

PyPI version    GitHub License

Python error boundary is a lightweight Python package that simplifies error handling by providing explicit, easy-to-understand error messages. Created for a personal project to make debugging more intuitive and less frustrating.


Installation

Install the package using pip:

pip install py_error_boundary

Description

The ErrorBoundary class takes a callable function along with all its required parameters as class arguments. Using these, the class invokes your function. For example:

ErrorBoundary(callable, param1, param2, ..., n)

Example:

import requests
from py_error_boundary.error_boundary import ErrorBoundary

# Initialize ErrorBoundary instance
obj = ErrorBoundary()

# Define whatever function you want to call
url = 'http://www.example.com'
def get(url):
    return requests.get(url)

# Call the function using ErrorBoundary, passing the function and arguments
print(obj(get, url))

Output

An exception occurred at line 12 in file req.py.
Error: Invalid URL 'www.example.com': No scheme supplied. Perhaps you meant https://www.example.com?

What’s happening:

  1. ErrorBoundary Class: The ErrorBoundary class is initialized with the function (get) and its parameters (url), and it executes the function while handling any errors.
  2. Invalid URL: In this case, the URL 'www.example.com' is missing a scheme (such as 'http://' or 'https://'), which causes a requests exception to be raised.
  3. Error Handling: The ErrorBoundary class catches the exception and provides detailed information about the error, including:
    • The exact line where the error occurred (line 12 in req.py).
    • A clear error message: "Invalid URL 'www.example.com': No scheme supplied. Perhaps you meant https://www.example.com?"

🚨 Important:

The ErrorBoundary class typically returns the file names for most environments, but if used in an interactive Python environment (e.g., the Python shell or Jupyter notebooks), it will return <stdin> as the file name. This is not an error, but rather a result of how the Python environment handles code execution in interactive sessions.


Cloning the repository

  • Clone
    git clone git@github.com:suyogkulkarnigit/py_error_boundary.git
    
  • Dist Setup
    make setup
    
  • Cleanup Setup
    make clean-setup
    

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

py_error_boundary-0.1.1.tar.gz (6.8 kB view details)

Uploaded Source

File details

Details for the file py_error_boundary-0.1.1.tar.gz.

File metadata

  • Download URL: py_error_boundary-0.1.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.6

File hashes

Hashes for py_error_boundary-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dd4f7685e83f68667f21f255bcf9b8d1b96a40d58ae4de239c5c97fe53197178
MD5 5824bda11350fe46738a942de91c3536
BLAKE2b-256 87950b2bd57b9d131997fd53822213fabeccb054f6de5225ef4e788f252392dc

See more details on using hashes here.

Supported by

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