Skip to content

Improve AttributeError message in XmlLayer when accessing missing fields #735

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rshayer95
Copy link

Summary

This PR improves the AttributeError raised in XmlLayer.__getattr__ when accessing a non-existent field.

Instead of a generic exception, the updated message includes:

  • The name of the missing field
  • The current layer name
  • A list of available field names in that layer

This enhancement improves the developer experience by making debugging much easier when interacting with parsed packet data.

File Changed

  • pyshark/src/pyshark/packet/layers/xml_layer.py

Line 79 Modified

  • Changed from:
    raise AttributeError()
  • Changed to:
    raise AttributeError(f"Field '{item}' not found in layer '{self.layer_name}'. Available fields: {', '.join(self.field_names)}")

… fields

Raises AttributeError with a helpful message when accessing a non-existent field
in XmlLayer. The message includes the field name, layer name, and available fields.

Fixes KimiNewt#733
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.

1 participant