Escape surrogate values in tracing output - #684
Open
Himanshuagrawal4 wants to merge 1 commit into
Open
Conversation
Himanshuagrawal4
marked this pull request as ready for review
June 4, 2026 19:35
RonnyPfannschmidt
added a commit
to RonnyPfannschmidt/pluggy
that referenced
this pull request
Sep 12, 2026
Tracing could turn a working hook call into a failing one in two ways: an object whose __repr__/__str__ raises propagated that exception out of the hook call (pytest-dev#424), and a lone surrogate in a hook argument or return value produced a message the writer could not encode (pytest-dev#681). Both are now handled in one place. _safe_repr()/_safe_str() wrap the conversion the way pytest's saferepr does -- KeyboardInterrupt and SystemExit still propagate, anything else is rendered as an unpresentable-object marker -- and escape lone surrogates with backslashreplace afterwards, which also covers surrogates that come out of an object's own __repr__. Traced values -- hook kwargs and the hook result -- now use repr() so their type is visible in the log; structural labels such as the hook name and the finish/--> markers keep using str() and stay unquoted. Supersedes pytest-dev#627, pytest-dev#666, pytest-dev#684 and pytest-dev#716. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
epr() for hook kwarg values in trace output so surrogate characters are escaped safely.
Tests
Fixes #681.