Include relevant values in ReadBuf.put_slice() panic message #6580
Labels
A-tokio
Area: The main tokio crate
C-feature-accepted
Category: A feature request that has been accepted pending implementation.
C-feature-request
Category: A feature request.
M-io
Module: tokio/io
Is your feature request related to a problem? Please describe.
A service I work on panicked due to the assert at the top of io::ReadBuf::put_slice(), however, the panic message did not include the values that were compared, which would help with debugging the problem.
Describe the solution you'd like
If calling
put_slice()
panics as a result the remaining space in the ReadBuf being less than the slice's length, it would be nice for the panic message to include the values ofself.remaining()
andbuf.len()
. This is the assert in question. I would propose updating it to something likeDescribe alternatives you've considered
Additional logging of these values can be done by users of this function. I suppose it could also return a
Result
with an error that contains the mismatch but that's a much bigger change that probably has its own downsides.Additional context
There does seem to be a number of these asserts scattered around tokio and I couldn't find any that included the errant values in the message for a greater than/less than check. If including the values in the error message is a desirable behavior, then it may be worth thinking about adding/using assert macros like assert_eq! for the various greater than/less than comparisons (assert_ge!, assert_le!, etc).
The text was updated successfully, but these errors were encountered: