Skip to content

Commit

Permalink
chore: add disk stat error wrapping
Browse files Browse the repository at this point in the history
While doing some debugging, realized we weren't doing any disk wrapping
so it was difficult to work out *which* file on disk didn't exist.

Signed-off-by: Justin Chadwell <[email protected]>
  • Loading branch information
jedevc committed Oct 21, 2024
1 parent f835dd4 commit 612332c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion util/disk/disk_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package disk

import (
"syscall"

"github.com/pkg/errors"
)

func GetDiskStat(root string) (DiskStat, error) {
var st syscall.Statfs_t
if err := syscall.Statfs(root, &st); err != nil {
return DiskStat{}, err
return DiskStat{}, errors.Wrapf(err, "could not stat fs at %s", root)
}

return DiskStat{
Expand Down
4 changes: 3 additions & 1 deletion util/disk/disk_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package disk

import (
"syscall"

"github.com/pkg/errors"
)

func GetDiskStat(root string) (DiskStat, error) {
var st syscall.Statfs_t
if err := syscall.Statfs(root, &st); err != nil {
return DiskStat{}, err
return DiskStat{}, errors.Wrapf(err, "could not stat fs at %s", root)
}

return DiskStat{
Expand Down
5 changes: 3 additions & 2 deletions util/disk/disk_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
package disk

import (
"github.com/pkg/errors"
"golang.org/x/sys/windows"
)

func GetDiskStat(root string) (DiskStat, error) {
rootUTF16, err := windows.UTF16FromString(root)
if err != nil {
return DiskStat{}, err
return DiskStat{}, errors.Wrapf(err, "could not encode %s", root)
}
var (
totalBytes uint64
Expand All @@ -22,7 +23,7 @@ func GetDiskStat(root string) (DiskStat, error) {
&freeAvailableBytes,
&totalBytes,
&totalFreeBytes); err != nil {
return DiskStat{}, err
return DiskStat{}, errors.Wrapf(err, "could not stat fs at %s", root)
}

return DiskStat{
Expand Down

0 comments on commit 612332c

Please sign in to comment.