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

Do not wrap errors from filepath / os as they are already wrapped. #109

Merged
merged 1 commit into from Apr 7, 2022
Merged
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
7 changes: 3 additions & 4 deletions mountinfo/mounted_unix.go
Expand Up @@ -4,7 +4,6 @@
package mountinfo

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -33,13 +32,13 @@ func mountedByStat(path string) (bool, error) {

func normalizePath(path string) (realPath string, err error) {
if realPath, err = filepath.Abs(path); err != nil {
return "", fmt.Errorf("unable to get absolute path for %q: %w", path, err)
return "", err
}
if realPath, err = filepath.EvalSymlinks(realPath); err != nil {
return "", fmt.Errorf("failed to canonicalise path for %q: %w", path, err)
return "", err
}
if _, err := os.Stat(realPath); err != nil {
return "", fmt.Errorf("failed to stat target of %q: %w", path, err)
return "", err
Comment on lines -36 to +41
Copy link
Collaborator

Choose a reason for hiding this comment

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

This part of patch might actually make sense (since the errors from os.Stat and filepath are probably already wrapped).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, os.IsNotExist() does not work for errors wrapped using %w (see https://go.dev/play/p/RcpXLGqwO9l), and since

  • both filepath.EvalSymlinks and os.Stat already contain path in their error message;
  • filepath.Abs can only return an error from os.Getwd() which is already descriptive enough,
    this part of patch does makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

Also, os.IsNotExist() does not work for errors wrapped using %w (see https://go.dev/play/p/RcpXLGqwO9l), and since

The reverse is also true for some errors unfortunately (and based on the discussion in golang/go#39155, I doubt that'll change)

}
return realPath, nil
}
Expand Down