@dataclass exception classes: str(exc) empty and exc.args empty when raised with keyword message · Issue #757 · rendercv/rendercv · GitHub
Skip to content

@dataclass exception classes: str(exc) empty and exc.args empty when raised with keyword message #757

Description

@chirag127

Problem

RenderCVUserError, RenderCVUserValidationError, and RenderCVInternalError in src/rendercv/exception.py are decorated with @dataclass and inherit from ValueError/RuntimeError. When raised with the keyword form actually used throughout the codebase (e.g. RenderCVUserError(message=...)), str(exc) returns '' and exc.args is () because dataclass-generated __init__ never calls super().__init__(message).

Steps

from rendercv.exception import RenderCVUserError
try:
    raise RenderCVUserError(message='YAML file not found')
except RenderCVUserError as e:
    print(repr(e.args), repr(str(e)))

Expected

('YAML file not found',) 'YAML file not found'

Actual

() ''

Any path where these exceptions escape the handle_user_errors decorator (library use, uncaught bubbling, third-party logging) shows a nameless RenderCVUserError in the traceback with no message. Real call sites use kw form: src/rendercv/cli/render_command/run_rendercv.py:188,196.

Environment

rendercv 2.8 (pyproject.toml), Python >=3.12. File: src/rendercv/exception.py:40-70.

Fix sketch

Add __post_init__ calling super().__init__(self.message), or drop @dataclass and use plain __init__.

Thanks for maintaining rendercv/rendercv!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions