lib/filestream: transform Open() -> MustOpen()

Callers of this function log the returned error and exit.
Let's log the error with the path to the filename and call stack
inside the function. This simplifies the code at callers' side
without reducing the level of debuggability.
This commit is contained in:
Aliaksandr Valialkin
2023-04-14 15:03:39 -07:00
parent fda1a54343
commit 5eb163a08a
7 changed files with 23 additions and 78 deletions

View File

@@ -100,10 +100,7 @@ func (q *queue) mustResetFiles() {
q.writer = w
q.readerPath = q.writerPath
r, err := filestream.Open(q.readerPath, true)
if err != nil {
logger.Panicf("FATAL: cannot open chunk file %q: %s", q.readerPath, err)
}
r := filestream.MustOpen(q.readerPath, true)
q.reader = r
if err := q.flushMetainfo(); err != nil {
@@ -559,10 +556,7 @@ func (q *queue) nextChunkFileForRead() error {
}
q.readerLocalOffset = 0
q.readerPath = q.chunkFilePath(q.readerOffset)
r, err := filestream.Open(q.readerPath, true)
if err != nil {
return fmt.Errorf("cannot open chunk file %q: %w", q.readerPath, err)
}
r := filestream.MustOpen(q.readerPath, true)
q.reader = r
if err := q.flushMetainfo(); err != nil {
return fmt.Errorf("cannot flush metainfo: %w", err)