Skip to content

Conversation

crStiv
Copy link

@crStiv crStiv commented Jul 26, 2025

What I did

Enhanced the clarity of exception messages raised during function export collisions in visit_ExportsDecl and _add_exposed_function.

How I did it

  • Wrapped the add_member call in a try-except block to catch NamespaceCollision and re-raise with a more descriptive message including the name of the export.

  • Updated StructureException to include the export name when a function is already exported.

How to verify it

Run the affected test cases in test_exports.py. Verify that the exceptions now provide more detailed messages referencing the specific export that caused the conflict.

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Improved the clarity of error messages raised during export collisions in module analysis by including the export name in the exception messages.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

Comment on lines 569 to 577
try:
self._self_t.typ.add_member(func_t.name, func_t)
except NamespaceCollision as e:
export_name = item.node_source_code
# Re-raise with more specific message mentioning the export
raise NamespaceCollision(
f"Member '{func_t.name}' already exists in self (when exporting `{export_name}`)",
prev_decl=e.prev_decl
) from e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this try/catch block seems a little ad hoc to me. would it be better to fix it at the source (where NamespaceCollision is raised in the first place)?

@crStiv crStiv requested a review from charles-cooper August 14, 2025 07:11
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

Successfully merging this pull request may close these issues.

2 participants