Skip to content

Commit 322b993

Browse files
committed
Ditch pkg/errors, use native error (un)wrapping
Compatibility notes: 1. ErrSymlinkLoop is removed in favor of wrapping syscall.ELOOP into &os.PathError{}; users should use e.g. errors.Is(err, syscall.ELOOP) to check for this particular error. 2. IsNotExist now does not use pkg/errors.Cause but native go error unwrapping; it could breaks a use case when it is used for some third-party errors wrapped using pkg/errors.Wrap[f]. I was not able to find any users of either feature. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 90b5819 commit 322b993

File tree

6 files changed

+4
-535
lines changed

6 files changed

+4
-535
lines changed

join.go

+3-22
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,20 @@ package securejoin
1212

1313
import (
1414
"bytes"
15+
"errors"
1516
"os"
1617
"path/filepath"
1718
"strings"
1819
"syscall"
19-
20-
"github.com/pkg/errors"
2120
)
2221

23-
// ErrSymlinkLoop is returned by SecureJoinVFS when too many symlinks have been
24-
// evaluated in attempting to securely join the two given paths.
25-
var ErrSymlinkLoop = errors.Wrap(syscall.ELOOP, "secure join")
26-
2722
// IsNotExist tells you if err is an error that implies that either the path
2823
// accessed does not exist (or path components don't exist). This is
2924
// effectively a more broad version of os.IsNotExist.
3025
func IsNotExist(err error) bool {
31-
// If it's a bone-fide ENOENT just bail.
32-
if os.IsNotExist(errors.Cause(err)) {
33-
return true
34-
}
35-
3626
// Check that it's not actually an ENOTDIR, which in some cases is a more
3727
// convoluted case of ENOENT (usually involving weird paths).
38-
var errno error
39-
switch err := errors.Cause(err).(type) {
40-
case *os.PathError:
41-
errno = err.Err
42-
case *os.LinkError:
43-
errno = err.Err
44-
case *os.SyscallError:
45-
errno = err.Err
46-
}
47-
return errno == syscall.ENOTDIR || errno == syscall.ENOENT
28+
return errors.Is(err, os.ErrNotExist) || errors.Is(err, syscall.ENOTDIR) || errors.Is(err, syscall.ENOENT)
4829
}
4930

5031
// SecureJoinVFS joins the two given path components (similar to Join) except
@@ -68,7 +49,7 @@ func SecureJoinVFS(root, unsafePath string, vfs VFS) (string, error) {
6849
n := 0
6950
for unsafePath != "" {
7051
if n > 255 {
71-
return "", ErrSymlinkLoop
52+
return "", &os.PathError{Op: "SecureJoin", Path: root + "/" + unsafePath, Err: syscall.ELOOP}
7253
}
7354

7455
// Next path component, p.

join_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func TestSymlinkLoop(t *testing.T) {
187187
{dir, "/self/././.."},
188188
} {
189189
got, err := SecureJoin(test.root, test.unsafe)
190-
if err != ErrSymlinkLoop {
190+
if !errors.Is(err, syscall.ELOOP) {
191191
t.Errorf("securejoin(%q, %q): expected ELOOP, got %v & %q", test.root, test.unsafe, err, got)
192192
continue
193193
}

vendor.conf

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
github.com/pkg/errors v0.8.0

vendor/github.com/pkg/errors/LICENSE

-23
This file was deleted.

vendor/github.com/pkg/errors/errors.go

-310
This file was deleted.

0 commit comments

Comments
 (0)