Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Improve affix_stack error on Affix file / class name mismatch #63

@choksi81

Description

@choksi81

If the file containing an Affix component class is not named class name (in lower case) + .r2py, then calling affix_stack.find_and_register_affix might succeed importing, but fail registering internally the component, and throw a rather unspecific KeyError.

In the code leading to the traceback below,

  • transparenttcprelayaffix.r2py defines a class Transparent_TCPRelayAffix;
  • the user code tries to instantiate an Affix stack including TransparentTCPRelayAffix (which yields the filename when .lowered, but is not the class name), and
  • when affix_stack.find_and_register_affix tries to copy the Affix's _context, that context (named after the class) doesn't exist, resulting in the KeyError.

It would be a good idea to check for this mismatch, and raise a more descriptive error message. (I assume a developer running unit tests would catch it very early on in the development, and trivially correct this mistake).

Uncaught exception! --- Following is a full traceback, and a user traceback. The user traceback excludes non-user modules. The most recent call is displayed last. Full debugging traceback: "repy.py", line 154, in execute_namespace_until_completion "/private/tmp/affix/RUNNABLE/virtual_namespace.py", line 117, in evaluate "/private/tmp/affix/RUNNABLE/safe.py", line 588, in safe_run "dylink.r2py", line 546, in <module> "dylink.r2py", line 407, in dylink_dispatch "dylink.r2py", line 520, in evaluate "/private/tmp/affix/RUNNABLE/virtual_namespace.py", line 117, in evaluate "/private/tmp/affix/RUNNABLE/safe.py", line 588, in safe_run "test-ttr.r2py", line 5, in <module> "affix_stack.r2py", line 32, in __init__ "affix_stack.r2py", line 133, in build_stack "affix_stack.r2py", line 218, in find_and_register_affix "/private/tmp/affix/RUNNABLE/safe.py", line 678, in __getitem__ User traceback: "dylink.r2py", line 546, in <module> "dylink.r2py", line 407, in dylink_dispatch "dylink.r2py", line 520, in evaluate "test-ttr.r2py", line 5, in <module> "affix_stack.r2py", line 32, in __init__ "affix_stack.r2py", line 133, in build_stack "affix_stack.r2py", line 218, in find_and_register_affix Exception (with type 'exceptions.KeyError'): 'Transparent_TCPRelayAffix' 

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