Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions unmount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func unmount(dir string) error {
if strings.HasPrefix(dir, "/dev/fd/") {
return fmt.Errorf("%w: %s", ErrExternallyManagedMountPoint, err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not possible or not desirable to wrap both errors here ? e.g. something like

Suggested change
return fmt.Errorf("%w: %s", ErrExternallyManagedMountPoint, err)
return fmt.Errorf("%w: %w", ErrExternallyManagedMountPoint, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, not desirable. Also, Unwrap doesn't work in multi %w scenario - https://go.dev/play/p/3aixFmasPAK

Copy link

@gargnitingoogle gargnitingoogle Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the sample you attached (thanks for it BTW), I see that the errors.Is returns true for both errors on the combined error, but errors.Wrap return nil on it, which is surprizing a bit.

Error: externally managed mount point: EOF
  errors.Is(errWW, ErrExternallyManagedMountPoint): true
  errors.Is(errWW, ErrUnderlying): true
  errors.Unwrap(errWW): <nil>

I am just worried that not wrapping the returned error on the original error would just lose information. There is a way to wrap multiple errors, that can be also be returned using UnWrap e.g. in this sample https://go.dev/play/p/VarDGW6zVe6 , but it's definitely not very easy to use. It returns this:

  errors.Is(errWW, ErrExternallyManagedMountPoint): true
  errors.Is(errWW, ErrUnderlying): true
Unwrapped error 1: externally managed mount point
Unwrapped error 2: EOF

}
return err
}
return nil
}
Expand Down
7 changes: 5 additions & 2 deletions unmount_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ func Test_umountNoCustomError(t *testing.T) {
t.Setenv("PATH", "") // Clear PATH to fail unmount with fusermount is not found

err := unmount("/dev")
if err != nil && errors.Is(err, ErrExternallyManagedMountPoint) {
t.Errorf("Not expected custom error.")
if err == nil {
t.Fatal("Expected error but got none.")
}
if errors.Is(err, ErrExternallyManagedMountPoint) {
t.Error("Custom error was not expected.")
}
}
Loading