{"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":"exception","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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/filters/__init__.py#L765-L801","documentation":"Raised by RaiseOnErrorTokenFilter when the `excclass` option is not a subclass of Exception (or not a class at all). The constructor runs issubclass(self.exception, Exception); if that raises TypeError (non-class or wrong hierarchy) the filter re-raises it as OptionError. The filter uses this class to raise when the lexer emits an Error token.","triggerScenarios":"Constructing RaiseOnErrorTokenFilter(excclass=<not-a-class>) directly, or via get_filter_by_name('raiseonerror', excclass='MyError') (a string), or passing a class that does not inherit Exception such as excclass=int.","commonSituations":"Passing a string class name instead of the class object (common when deserializing options from config/CLI); passing a custom error class that forgets to subclass Exception; typos in the option key.","solutions":["Pass an actual Exception subclass object, e.g. excclass=ValueError, not its name.","Omit excclass entirely to use the default pygments.filters.ErrorToken.","Validate the value with issubclass(x, Exception) before passing it."],"exampleFix":"# before\nget_filter_by_name('raiseonerror', excclass='MyError')\n# after\nget_filter_by_name('raiseonerror', excclass=MyError)","handlingStrategy":"validation","validationCode":"from pygments.util import OptionError\ndef valid_excclass(x):\n    return x is None or (isinstance(x, type) and issubclass(x, Exception))\n# before constructing the filter:\nif not valid_excclass(opts.get('excclass')):\n    raise ValueError('excclass must be an Exception subclass')","typeGuard":"import inspect\ndef is_exception_class(x):\n    return inspect.isclass(x) and issubclass(x, Exception)","tryCatchPattern":"from pygments.util import OptionError\ntry:\n    f = get_filter_by_name('raiseonerror', excclass=value)\nexcept OptionError as e:\n    # fall back to default error token behaviour\n    f = get_filter_by_name('raiseonerror')","preventionTips":["Always pass the class object, never its name.","Make custom error classes inherit Exception."],"tags":["pygments","filter","configuration","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}