{"id":8801,"library":"zope-exceptions","title":"Zope Exceptions","description":"This package provides general-purpose exception classes and implementations for the Zope ecosystem, designed to extend Python's standard `traceback` module with additional context information. It facilitates annotating tracebacks with `__traceback_info__` for unstructured data or `__traceback_supplement__` for delayed, structured data. It is currently at version 6.0 and receives updates primarily driven by Python version support and significant ecosystem changes, maintaining an active but irregular release cadence.","status":"active","version":"6.0","language":"python","source_language":"en","source_url":"https://github.com/zopefoundation/zope.exceptions","tags":["zope","exceptions","error handling","traceback","debugging"],"install":[{"cmd":"pip install zope-exceptions","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"format_exception","correct":"from zope.exceptions import format_exception"},{"note":"Used for advanced HTML-based traceback formatting.","symbol":"HTMLExceptionFormatter","correct":"from zope.exceptions.exceptionformatter import HTMLExceptionFormatter"},{"note":"Used for advanced plain-text traceback formatting.","symbol":"TextExceptionFormatter","correct":"from zope.exceptions.exceptionformatter import TextExceptionFormatter"}],"quickstart":{"code":"import sys\nfrom zope.exceptions import format_exception\n\ndef problematic_function(item_id):\n    __traceback_info__ = f\"Processing item with ID: {item_id}\" # Adds context to traceback\n    raise ValueError(f\"Failed to process item {item_id}\")\n\ntry:\n    problematic_function('XYZ-123')\nexcept Exception:\n    exc_type, exc_value, exc_traceback = sys.exc_info()\n    formatted_traceback = format_exception(exc_type, exc_value, exc_traceback)\n    print(\"\\n\".join(formatted_traceback))\n    del exc_traceback # Avoid reference cycles\n","lang":"python","description":"This quickstart demonstrates how to use `__traceback_info__` to inject context into an exception's traceback. The `format_exception` function then processes this enriched information for output, making debugging easier."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer, or pin `zope-exceptions<6.0` if you cannot upgrade Python.","message":"Version 6.0 and higher explicitly drop support for Python 3.8 and older. Ensure your project runs on Python 3.9 or newer.","severity":"breaking","affected_versions":"6.0+"},{"fix":"Ensure your `setuptools` is up-to-date and your environment correctly handles PEP 420 native namespace packages. Consider using modern virtual environment tools.","message":"Version 6.0 replaces `pkg_resources` namespace with PEP 420 native namespace for package discovery. This can impact environments relying on older `setuptools` or specific packaging setups.","severity":"breaking","affected_versions":"6.0+"},{"fix":"Upgrade your Python environment to 3.7 or newer, or pin `zope-exceptions<5.0` if you are on an unsupported Python version.","message":"Version 5.0 dropped support for Python 2.7, 3.5, and 3.6.","severity":"breaking","affected_versions":"5.0+"},{"fix":"For expensive context generation, use `__traceback_supplement__` instead. This variable takes a callable and its arguments, which are only evaluated if a traceback needs to be formatted, delaying the computation.","message":"The `__traceback_info__` variable is evaluated immediately, even if the traceback is never formatted. If generating this information is computationally expensive, it can introduce unnecessary runtime overhead.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When working with Zope, understand the specific exception handling mechanism for your Zope version (e.g., configuring exception views in ZCML for Zope 4+). `zope.errorview` is a related package that provides basic HTTP and Browser views for common exceptions in newer Zope versions.","message":"In older Zope 2.x environments, error handling often involved `standard_error_message` (a ZODB object). Zope 3/4 and modern WSGI setups transitioned to 'exception views' registered via ZCML. `zope.exceptions` provides low-level tools, but the high-level application error display depends on the broader Zope architecture.","severity":"gotcha","affected_versions":"Zope 2, 3, 4, 5+"}],"env_vars":null,"search_vec":"'6.0':51 'activ':67 'addit':26 'annot':31 'cadenc':71 'chang':64 'class':10 'context':27 'current':48 'data':38,45 'debug':77 'delay':43 'design':17 'driven':56 'ecosystem':16,63 'error':74 'except':2,9,73 'extend':19 'facilit':30 'general':7 'general-purpos':6 'handl':75 'implement':12 'info':35 'inform':28 'irregular':69 'maintain':65 'modul':24 'packag':4 'primarili':55 'provid':5 'purpos':8 'python':20,58 'receiv':53 'releas':70 'signific':62 'standard':22 'structur':44 'supplement':41 'support':60 'traceback':23,32,34,40,76 'unstructur':37 'updat':54 'version':50,59 'zope':1,15,72","created_at":"2026-04-16T17:04:04.891605+00:00","updated_at":"2026-04-16T17:04:04.891605+00:00","problems":[{"fix":"Ensure your Python environment uses `setuptools` compatible with PEP 420 native namespace packages. Upgrade `setuptools` to its latest version (`pip install --upgrade setuptools`) and consider using a fresh virtual environment.","cause":"The library (especially 6.0+) uses PEP 420 native namespaces, moving away from `pkg_resources` for namespace package discovery. Your environment might be outdated or configured to expect `pkg_resources` behavior.","error":"ImportError: cannot import name '...' from 'pkg_resources'"},{"fix":"Assign `__traceback_supplement__` a tuple `(my_callable, arg1, arg2, ...)` where `my_callable` is the function to be called, not `my_callable(arg1, arg2, ...)`. The function will be called only when the traceback is formatted.","cause":"The `__traceback_supplement__` variable expects a sequence (typically a tuple) where the first element is a callable (function or method) and subsequent elements are its arguments. Users often mistakenly provide the result of the callable instead.","error":"TypeError: 'str' object is not callable (when using __traceback_supplement__)"},{"fix":"Refactor your code to raise proper exception classes, such as `raise ValueError('My Error')`.","cause":"This warning occurs in older Python 2.x Zope environments when exceptions are raised as string literals (e.g., `raise 'My Error'`), a practice deprecated in Python 2.6 and removed in Python 3.","error":"DeprecationWarning: string exceptions are deprecated"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"6.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/zopefoundation/zope.exceptions","docs":null,"changelog":null,"pypi":"https://pypi.org/project/zope-exceptions/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}