code: func (w *SegmentWAL) truncate(err error, file int, lastOffset int64) error {
  	level.Error(w.logger).Log("msg", "WAL corruption detected; truncating",
  		"err", err, "file", w.files[file].Name(), "pos", lastOffset)
  
  	// Close and delete all files after the current one.
  	for _, f := range w.files[file+1:] {
  		if err := f.Close(); err != nil {
  			return err
  		}
  		if err := os.Remove(f.Name()); err != nil {
  			return err
  		}
  	}
  	w.mtx.Lock()
  	defer w.mtx.Unlock()
  
  	w.files = w.files[:file+1]
  
  	// Seek the current file to the last valid offset where we continue writing from.
  	_, err = w.files[file].Seek(lastOffset, io.SeekStart)
  	return err
  }
docs: // truncate the WAL after the last valid entry.