lib/fs: improve error logging at ReaderAt.MustReadAt()

- Add 'BUG:' prefix to error messages related to programming errors aka bugs.
- Consistently log the path to the file in all the messages in order to improve debuggability.
This commit is contained in:
Aliaksandr Valialkin 2023-04-14 14:51:03 -07:00
parent f341b7b3f8
commit fda1a54343
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -43,7 +43,7 @@ func (r *ReaderAt) MustReadAt(p []byte, off int64) {
return
}
if off < 0 {
logger.Panicf("off=%d cannot be negative", off)
logger.Panicf("BUG: off=%d cannot be negative", off)
}
if len(r.mmapData) == 0 {
n, err := r.f.ReadAt(p, off)
@ -51,11 +51,11 @@ func (r *ReaderAt) MustReadAt(p []byte, off int64) {
logger.Panicf("FATAL: cannot read %d bytes at offset %d of file %q: %s", len(p), off, r.f.Name(), err)
}
if n != len(p) {
logger.Panicf("FATAL: unexpected number of bytes read; got %d; want %d", n, len(p))
logger.Panicf("FATAL: unexpected number of bytes read from file %q; got %d; want %d", r.f.Name(), n, len(p))
}
} else {
if off > int64(len(r.mmapData)-len(p)) {
logger.Panicf("off=%d is out of allowed range [0...%d] for len(p)=%d", off, len(r.mmapData)-len(p), len(p))
logger.Panicf("BUG: off=%d is out of allowed range [0...%d] for len(p)=%d", off, len(r.mmapData)-len(p), len(p))
}
src := r.mmapData[off:]
// The copy() below may result in thread block as described at https://valyala.medium.com/mmap-in-go-considered-harmful-d92a25cb161d .