1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 // Portable analogs of some common system call errors.
13 ErrInvalid
= errors
.New("invalid argument")
14 ErrPermission
= errors
.New("permission denied")
15 ErrExist
= errors
.New("file already exists")
16 ErrNotExist
= errors
.New("file does not exist")
19 // PathError records an error and the operation and file path that caused it.
20 type PathError
struct {
26 func (e
*PathError
) Error() string { return e
.Op
+ " " + e
.Path
+ ": " + e
.Err
.Error() }
28 // SyscallError records an error from a specific system call.
29 type SyscallError
struct {
34 func (e
*SyscallError
) Error() string { return e
.Syscall
+ ": " + e
.Err
.Error() }
36 // NewSyscallError returns, as an error, a new SyscallError
37 // with the given system call name and error details.
38 // As a convenience, if err is nil, NewSyscallError returns nil.
39 func NewSyscallError(syscall
string, err error
) error
{
43 return &SyscallError
{syscall
, err
}
46 // IsExist returns a boolean indicating whether the error is known to report
47 // that a file or directory already exists. It is satisfied by ErrExist as
48 // well as some syscall errors.
49 func IsExist(err error
) bool {
53 // IsNotExist returns a boolean indicating whether the error is known to
54 // report that a file or directory does not exist. It is satisfied by
55 // ErrNotExist as well as some syscall errors.
56 func IsNotExist(err error
) bool {
57 return isNotExist(err
)
60 // IsPermission returns a boolean indicating whether the error is known to
61 // report that permission is denied. It is satisfied by ErrPermission as well
62 // as some syscall errors.
63 func IsPermission(err error
) bool {
64 return isPermission(err
)