limit the context for convert_error
#1868
Open
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.
Besides the panic with the current implementation, I don't think it's reasonable to try displaying to the user a single line of text over 0xffff bytes long followed by another line with over 0xffff leading space characters. In a terminal or another environment where word wrap is enabled, your display would need to be hundreds of thousands of pixels wide to see the cursor on the second line match the error on the first line.
Instead, I added the column number after the line number, and limited the number of preceding and following bytes to 40.
Taking substrings like this has the potential for new panics related to utf-8, so I also added a test for when the surrounding characters are 3-byte UTF-8 sequences and taking 40 bytes would cause a panic. The test behaves as expected, but demonstrates another problem with the
convert_errorfunction: it uses the length of the string in bytes to determine the column number. This won't line up if there are multibyte characters or if there are combining characters or if there are double width characters. Proper handling of multibyte characters would be relatively simple, but IIRC measuring the width of a string in columns is a more complicated problem that would likely involve bringing in a crate specifically for that purpose.Fixes #1867