Stop including string content in index panics?
HI Rust!
At Zed (https://zed.dev) we track panics in a centralized system so that we can identify and fix problems.
A major cause of panics at Zed is indexing into strings erroneously (we do a lot of string manipulation); usually due to bad utf8 offset handling, or occasionally just off by one or out-of-bounds.
The problem is that String when it panics includes a small fragment of the string. This can be useful locally for debugging, but for centralized panic tracking, we'd really like to not handle this stuff.
Is there appetite to either:
- Add a flag to the standard library to suppress this.
- Change the default panic messages to not include content.
For example
- currently we see: "begin <= end (4 <= 3) when slicing
test. I'd like this to become "byte index range starts before end (4..3)" - "byte index 2458645928158 is out of bounds of
test". I'd like this to become "byte index 2458645928158 is out of bounds for string of length 4" - "byte index 1 is not a char boundary; it is inside 'ã' (bytes 0..2) of
ãchoo. I'd like this to become "byte index 1 is not at a utf-8 character boundary; the character spans from indexes 0..2)"
The alternative we can explore is trying to replace the strings on the way through the panic handler (or forbid indexing into a string - doesn't seem tenable); but I'd rather push this down to the standard library.
Discussion in the ATmosphere