better failure message when failing to detect compressor on compressed transport stream

This commit is contained in:
Shay Banon 2012-07-01 18:34:58 +02:00
parent e5c89def42
commit 743d3f7e4b
1 changed files with 8 additions and 1 deletions

View File

@ -222,7 +222,14 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler {
if (TransportStreams.statusIsCompress(status) && buffer.readable()) { if (TransportStreams.statusIsCompress(status) && buffer.readable()) {
Compressor compressor = CompressorFactory.compressor(buffer); Compressor compressor = CompressorFactory.compressor(buffer);
if (compressor == null) { if (compressor == null) {
throw new ElasticSearchIllegalStateException("stream marked as compressed, but no compressor found"); int maxToRead = Math.min(buffer.readableBytes(), 10);
int offset = buffer.readerIndex();
StringBuilder sb = new StringBuilder("stream marked as compressed, but no compressor found, first [").append(maxToRead).append("] content bytes out of [").append(buffer.readableBytes()).append("] are [");
for (int i = 0; i < maxToRead; i++) {
sb.append(buffer.getByte(offset + i)).append(",");
}
sb.append("]");
throw new ElasticSearchIllegalStateException(sb.toString());
} }
wrappedStream = CachedStreamInput.cachedHandlesCompressed(compressor, streamIn); wrappedStream = CachedStreamInput.cachedHandlesCompressed(compressor, streamIn);
} else { } else {