Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str and repr can throw #108

Open
thirtytwobits opened this issue Jul 12, 2024 · 1 comment
Open

str and repr can throw #108

thirtytwobits opened this issue Jul 12, 2024 · 1 comment

Comments

@thirtytwobits
Copy link
Member

Some objects in pydsdl can throw attribute errors when repr() or str() is called on them This leads to confusing error messaging when tools attempt to log exceptions thrown in initializers. For example, DSDLDefinition throws if the provided arguments are malformed. Seen in the wild is this debug output:

../pydsdl/pydsdl/_namespace.py:204: in read_files
    target_dsdl_definitions = _construct_dsdl_definitions_from_files(
../pydsdl/pydsdl/_namespace.py:345: in _construct_dsdl_definitions_from_files
    output.add(_dsdl_definition.DSDLDefinition.from_first_in(resolved_fp, list(valid_roots)))
../pydsdl/pydsdl/_dsdl_definition.py:116: in from_first_in
    return cls(dsdl_path, cls._infer_path_to_root_from_first_found(dsdl_path, valid_dsdl_roots))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <[AttributeError("'DSDLDefinition' object has no attribute '_name'") raised in repr()] DSDLDefinition object at 0x102d46b10>

    def __init__(self, file_path: Path, root_namespace_path: Path):
        """ """
        # Normalizing the path and reading the definition text

...

Suggested change:

def __str__(self) -> str:
  try:
      return "DSDLDefinition(full_name=%r, version=%r, fixed_port_id=%r, file_path=%s)" % (
          self.full_name,
          self.version,
          self.fixed_port_id,
          self.file_path,
      )
  except AttributeError:
      return "DSDLDefinition(UNINITIALIZED)"
@thirtytwobits
Copy link
Member Author

DSDLDefinition example was fixed along with change to fix #109. Keeping this issue open to scrub the code base for similar issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant