-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conversation
13957d6
to
b521653
Compare
Hmm bit on the fence on this one; we'll lose some context on the errors, and
|
Yep! This is because there is a lot of old code that relies os.ErrNotExist in k8s (see: kubernetes/kubernetes@49f76c3) and it is proving incredibly hard to unwrap them and maintain compatibility. os.IsNotExist is not the only error; there is os.IsPermission that it relies on. |
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 |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
andos.Stat
already contain path in their error message; filepath.Abs
can only return an error fromos.Getwd()
which is already descriptive enough,
this part of patch does makes sense.
There was a problem hiding this comment.
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)
@manugupt1 I do not understand the need for change; Please see the following example that works as expected: https://go.dev/play/p/kAy9rCXZaW4 If something is not working like you think it should, can you please provide the example similar to mine? |
I stand corrected -- part of this PR actually makes sense (see https://github.com/moby/sys/pull/109#discussion_r843415781https://github.com/moby/sys/pull/109#discussion_r843415781) |
Hi Kir, |
On Tue, Apr 5, 2022, 21:44 Manu Gupta ***@***.***> wrote:
I had the following examples when I was testing: Wrapping with &os.PathError{err:
Err} also returns false
https://go.dev/play/p/n156HDTShUu
Well, the error from os.Lstat is already an os.PathError, and it is
obviously a bug to wrap it in another os.PathError, so the example code is
wrong.
The code in this repo only wraps errors from unix into os.PathError, as
errors from unix are bare errnos.
… |
@manugupt1 can you adopt the commit accordingly (i.e. only leave the part that patches |
and fix the commit description accordingly (saying that errors from |
233b438
to
9edc129
Compare
Since errors from filepath/ost are already wrapped, they do not need to be wrapped again. Wrapping them again will cause os.IsErrNotExist(err) to return false while some providers may want it to be true. Signed-off-by: Manu Gupta <manugupt1@gmail.com>
9edc129
to
4ac34a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
While trying to import MountedFast into k8s to detect mount points
using openat2, several tests failed because they rely on
os.IsErrNotExist / os.IsPermission which do not actually test the
underlying error.
For a non-existent path, if we return the bare error, this problem
is solved. I tested for the following cases to ensure that
backward compatibility is not broken: