Skip to content

feat: human-readable path formatting in NodeTypeError messages#40

Merged
nathanjmcdougall merged 4 commits into
mainfrom
37-error-messages-expose-raw-tuple-repr-in-nodetypeerror
May 22, 2026
Merged

feat: human-readable path formatting in NodeTypeError messages#40
nathanjmcdougall merged 4 commits into
mainfrom
37-error-messages-expose-raw-tuple-repr-in-nodetypeerror

Conversation

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

Summary

Replace raw tuple repr in NodeTypeError messages with human-readable path strings.

Before: Value at ('repos', 0, 'steps') is not a list
After: Value at repos > 0 > steps is not a list

Changes

  • New src/yamltrip/_display.py module with format_path helper
  • Updated 3 call sites in document.py: remove_from_list, ensure_in_list, find_index
  • Tests for format_path and error message formatting

Closes #37

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves NodeTypeError usability by replacing raw Python tuple representations of key paths (e.g., ('repos', 0, 'steps')) with a human-readable path string (e.g., repos > 0 > steps) in error messages emitted from Document list operations.

Changes:

  • Added yamltrip._display.format_path() to format (str|int, ...) key tuples into a > 0 > b path strings (with <root> for ()).
  • Updated Document.remove_from_list, Document.ensure_in_list, and Document.find_index to use format_path(keys) in their NodeTypeError messages.
  • Added focused unit tests for format_path and for the updated NodeTypeError message formatting.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/yamltrip/_display.py Introduces format_path() helper for human-readable key-path formatting.
src/yamltrip/document.py Switches NodeTypeError message interpolation to use format_path() at three call sites.
tests/test_display.py Adds unit tests covering format_path() behavior (single key, multi-key, int index, root).
tests/test_document.py Adds assertions that list-operation NodeTypeError messages use the new path formatting.
doc/specs/2026-05-22-error-message-tuple-repr-design.md Documents the problem, chosen formatting, and scope/testing plan.
.importlinter Updates import-linter configuration to account for the new internal _display module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread doc/specs/2026-05-22-error-message-tuple-repr-design.md
@nathanjmcdougall nathanjmcdougall merged commit 804fc8d into main May 22, 2026
18 checks passed
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.

Error messages expose raw tuple repr in NodeTypeError

2 participants