Skip to content

fix: guard against AttributeError when node lacks id in error messages#929

Open
armorbreak001 wants to merge 1 commit intoyaml:mainfrom
armorbreak001:fix/constructor-error-node-id
Open

fix: guard against AttributeError when node lacks id in error messages#929
armorbreak001 wants to merge 1 commit intoyaml:mainfrom
armorbreak001:fix/constructor-error-node-id

Conversation

@armorbreak001
Copy link
Copy Markdown

Summary

Closes #907

When construct_scalar, construct_sequence, construct_mapping, etc. receive a non-Node object (e.g., None, a plain Python object), the error handler unconditionally accesses node.id which raises AttributeError, masking the intended ConstructorError.

Changes

Replace direct node.id / subnode.id / value_node.id access in all ConstructorError messages with getattr(node, 'id', repr(node)). This ensures the descriptive error is always raised regardless of whether the input is a proper Node instance.

Details

Affected methods in lib/yaml/constructor.py:

  • BaseConstructor.construct_scalar
  • BaseConstructor.construct_sequence
  • BaseConstructor.construct_mapping
  • BaseConstructor.construct_pairs
  • SafeConstructor.flatten_mapping (subnode, value_node)
  • SafeConstructor.construct_yaml_omap (node, subnode)
  • SafeConstructor.construct_yaml_pairs (node, subnode)

All 1283 existing tests pass.

…ror messages

When construct_scalar/construct_sequence/construct_mapping etc. receive
a non-Node object (e.g., None, a plain Python object), the error
handler unconditionally accesses node.id which raises AttributeError,
masking the original ConstructorError. Use getattr with a repr()
fallback so the intended error is always raised.
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.

ConstructorError handler accesses node.id causing AttributeError

1 participant