Repository navigation
fix(azure): cap error details by characters so non-ASCII bodies don't panic - #805
Merged
martintrojer merged 1 commit intoOct 26, 2026
Conversation
… panic `trim_detail` capped an Azure DevOps error body with `&collapsed[..400]`, a byte slice. When byte 400 fell inside a multi-byte character, the slice panicked instead of producing the error message. Error bodies are not guaranteed to be ASCII: they can quote repository or user names, or be HTML error pages. The Gerrit backend's copy of this helper already caps by characters for exactly this reason. Use the same implementation here, with the same 400-character limit named as `MAX_DETAIL_CHARS`. ASCII bodies are trimmed exactly as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
|
Thanks! |
1 task
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.
Problem
When an Azure DevOps request fails with a long error body, tuicr can panic instead of showing the error.
map_http_errorpasses every failed response body (andaz reststderr) throughtrim_detail, and that function capped the text with a byte slice:If byte 400 falls inside a multi-byte character,
&collapsed[..400]panics with "byte index 400 is not a char boundary". Error bodies are not guaranteed to be ASCII: they can quote repository or user names, or be HTML error pages.tuicr pr <N>, the request runs on the main thread, so the panic ends tuicr.Cause
trim_detailinsrc/forge/azure/az.rsmeasures and slices in bytes. The Gerrit backend has its own copy of this helper insrc/forge/gerrit/api.rs, and that copy caps by characters for exactly this reason. Its regression test isshould_cap_error_detail_without_splitting_a_multi_byte_character. The Azure copy is older and was never updated.Fix
Use the Gerrit implementation as is: cut at
char_indices().nth(MAX_DETAIL_CHARS), with the 400 limit now namedMAX_DETAIL_CHARS. ASCII bodies are trimmed exactly as before (same length, same…). For non-ASCII text, the only change is that the cut now lands on a character boundary.Tests
trim_detail_caps_characters_without_splitting_a_multi_byte_characteris a copy of the Gerrit test. The input is 399afollowed by ten€, so byte 400 falls inside the first€. The old code panics on it. The new code keeps 400 characters and adds….trim_detail_leaves_short_detail_untrimmed_and_collapses_whitespacepins the existing whitespace collapsing.I don't have a Rust toolchain where I prepared this, so I have not compiled it or run
cargo test,cargo fmtorcargo clippyon this branch. CI will be the first build. The function body is byte-for-byte the same as the Gerrit one that is already onmain. I also checked the old and new logic with a small Python model of Rust's string slicing:🤖 Generated with Claude Code