Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide Read/Write system errors #390

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion host/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ func (vm *VolumeManager) Write(root types.Hash256, data *[rhp2.SectorSize]byte)
},
Timestamp: time.Now(),
})
return fmt.Errorf("failed to write sector data: %w", err)
return err
}
vm.log.Debug("wrote sector", zap.String("root", root.String()), zap.Int64("volume", loc.Volume), zap.Uint64("index", loc.Index), zap.Duration("elapsed", time.Since(start)))

Expand Down
13 changes: 13 additions & 0 deletions host/storage/verrors_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !windows
// +build !windows

package storage

import (
"errors"
"syscall"
)

func isNotEnoughStorageErr(err error) bool {
return errors.Is(err, syscall.ENOSPC)
}
14 changes: 14 additions & 0 deletions host/storage/verrors_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build windows
// +build windows

package storage

import (
"errors"

"golang.org/x/sys/windows"
)

func isNotEnoughStorageErr(err error) bool {
return errors.Is(err, windows.ERROR_DISK_FULL)
}
6 changes: 5 additions & 1 deletion host/storage/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ func (v *volume) WriteSector(data *[rhp2.SectorSize]byte, index uint64) error {
}
_, err := v.data.WriteAt(data[:], int64(index*rhp2.SectorSize))
if err != nil {
err = fmt.Errorf("failed to write sector to index %v: %w", index, err)
if isNotEnoughStorageErr(err) {
err = ErrNotEnoughStorage
} else {
err = fmt.Errorf("failed to write sector to index %v: %w", index, err)
}
}
go v.incrementWriteStats(err)
return err
Expand Down
9 changes: 6 additions & 3 deletions rhp/v3/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ func (pe *programExecutor) executeAppendSector(instr *rhp3.InstrAppendSector, lo
}

release, err := pe.storage.Write(root, sector)
if err != nil {
return nil, nil, fmt.Errorf("failed to write sector: %w", err)
if errors.Is(err, storage.ErrNotEnoughStorage) {
return nil, nil, err
} else if err != nil {
return nil, nil, ErrHostInternalError
}
pe.releaseFuncs = append(pe.releaseFuncs, release)
pe.updater.AppendSector(root)
Expand Down Expand Up @@ -275,7 +277,8 @@ func (pe *programExecutor) executeReadSector(instr *rhp3.InstrReadSector, log *z

sector, err := pe.storage.Read(root)
if err != nil {
return nil, nil, fmt.Errorf("failed to read sector %q: %w", root, err)
log.Error("failed to read sector", zap.String("root", root.String()), zap.Error(err))
return nil, nil, ErrHostInternalError
}

// if no proof was requested, return the data
Expand Down