Skip to content

Improve AttributeError message in XmlLayer when accessing missing fields#735

Open
rshayer95 wants to merge 1 commit intoKimiNewt:masterfrom
rshayer95:fix/733-missing-details-for-attribute-error
Open

Improve AttributeError message in XmlLayer when accessing missing fields#735
rshayer95 wants to merge 1 commit intoKimiNewt:masterfrom
rshayer95:fix/733-missing-details-for-attribute-error

Conversation

@rshayer95
Copy link
Copy Markdown

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