{"record":{"id":"0917b63a7c93c5a7","repo":"pypa/pip","slug":"excclass-option-is-not-an-exception-class","errorCode":null,"errorMessage":"excclass option is not an exception class","messagePattern":"excclass option is not an exception class","errorType":"validation","errorClass":"OptionError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/filters/__init__.py","lineNumber":783,"sourceCode":"\n    Options accepted:\n\n    `excclass` : Exception class\n      The exception class to raise.\n      The default is `pygments.filters.ErrorToken`.\n\n    .. versionadded:: 0.8\n    \"\"\"\n\n    def __init__(self, **options):\n        Filter.__init__(self, **options)\n        self.exception = options.get('excclass', ErrorToken)\n        try:\n            # issubclass() will raise TypeError if first argument is not a class\n            if not issubclass(self.exception, Exception):\n                raise TypeError\n        except TypeError:\n            raise OptionError('excclass option is not an exception class')\n\n    def filter(self, lexer, stream):\n        for ttype, value in stream:\n            if ttype is Error:\n                raise self.exception(value)\n            yield ttype, value\n\n\nclass VisibleWhitespaceFilter(Filter):\n    \"\"\"Convert tabs, newlines and/or spaces to visible characters.\n\n    Options accepted:\n\n    `spaces` : string or bool\n      If this is a one-character string, spaces will be replaces by this string.\n      If it is another true value, spaces will be replaced by ``·`` (unicode\n      MIDDLE DOT).  If it is a false value, spaces will not be replaced.  The\n      default is ``False``.","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pygments/filters/__init__.py#L765-L801","documentation":"Raised by RaiseOnErrorTokenFilter.__init__ when the 'excclass' option is not a subclass of Exception. The filter validates via issubclass(exception, Exception); if the value is not a class at all, issubclass raises TypeError which is caught and converted to OptionError. This ensures only valid exception classes are wired up to fire on error tokens.","triggerScenarios":"Passing get_filter_by_name('raiseonerror', excclass=SomeNonExceptionClass) or excclass='RuntimeError' (a string instead of the class), or excclass=1234. Any value that is not an Exception subclass trips the check at filters/__init__.py:778-783.","commonSituations":"Passing the exception name as a string instead of the class object; passing a BaseException subclass (not Exception); passing a non-class value; typos in the option key.","solutions":["Pass an actual Exception subclass class object: excclass=RuntimeError.","Omit excclass to use the default ErrorToken class.","Ensure the value is a class (type) and a subclass of Exception before passing."],"exampleFix":"# before\nget_filter_by_name('raiseonerror', excclass='RuntimeError')\n# after\nget_filter_by_name('raiseonerror', excclass=RuntimeError)","handlingStrategy":"validation","validationCode":"import inspect\nif excclass is not None and not (inspect.isclass(excclass) and issubclass(excclass, Exception)):\n    raise ValueError('excclass must be an Exception subclass')","typeGuard":"def is_exception_class(obj) -> bool:\n    import inspect\n    return inspect.isclass(obj) and issubclass(obj, Exception)","tryCatchPattern":"from pip._vendor.pygments.util import OptionError\ntry:\n    f = get_filter_by_name('raiseonerror', excclass=cls)\nexcept OptionError:\n    f = get_filter_by_name('raiseonerror')  # default excclass","preventionTips":["Pass the class object, never a string, for excclass.","Validate with issubclass(cls, Exception) before passing."],"tags":["python","pygments","filter","validation","vendored"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}