summaryrefslogtreecommitdiff
path: root/src/pkg/os/error.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-06-25 20:24:55 -0700
committerRuss Cox <rsc@golang.org>2009-06-25 20:24:55 -0700
commitb26cd1bfcd7107d8208595614ba45f54d5efacf6 (patch)
tree1596fd2f89c1d896cdf5772aebc910f4e0ff5bda /src/pkg/os/error.go
parent37fd11a43607dc5f7ff5c38311b060ada2a0e7a5 (diff)
downloadgolang-b26cd1bfcd7107d8208595614ba45f54d5efacf6.tar.gz
Change os.Error convention:
echo back context of call in error if likely to be useful. For example, if os.Open("/etc/passwd", os.O_RDONLY) fails with syscall.EPERM, it returns as the os.Error &PathError{ Op: "open", Path: "/etc/passwd" Error: os.EPERM } which formats as open /etc/passwd: permission denied Not converted: datafmt go/... google/... regexp tabwriter template R=r DELTA=1153 (561 added, 156 deleted, 436 changed) OCL=30738 CL=30781
Diffstat (limited to 'src/pkg/os/error.go')
-rw-r--r--src/pkg/os/error.go39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/pkg/os/error.go b/src/pkg/os/error.go
index 718499b21..10a7d042a 100644
--- a/src/pkg/os/error.go
+++ b/src/pkg/os/error.go
@@ -30,15 +30,6 @@ func (e Errno) String() string {
return syscall.Errstr(int(e))
}
-// ErrnoToError converts errno to an Error (underneath, an Errno).
-// It returns nil for the "no error" errno.
-func ErrnoToError(errno int) Error {
- if errno == 0 {
- return nil
- }
- return Errno(errno)
-}
-
// Commonly known Unix errors.
var (
EPERM Error = Errno(syscall.EPERM);
@@ -81,3 +72,33 @@ var (
ENAMETOOLONG Error = Errno(syscall.ENAMETOOLONG);
)
+// PathError records an error and the operation and file path that caused it.
+type PathError struct {
+ Op string;
+ Path string;
+ Error Error;
+}
+
+func (e *PathError) String() string {
+ return e.Op + " " + e.Path + ": " + e.Error.String();
+}
+
+// SyscallError records an error from a specific system call.
+type SyscallError struct {
+ Syscall string;
+ Errno Errno;
+}
+
+func (e *SyscallError) String() string {
+ return e.Syscall + ": " + e.Errno.String();
+}
+
+// NewSyscallError returns, as an os.Error, a new SyscallError
+// with the given system call name and error number.
+// As a convenience, if errno is 0, NewSyscallError returns nil.
+func NewSyscallError(syscall string, errno int) os.Error {
+ if errno == 0 {
+ return nil;
+ }
+ return &SyscallError{syscall, Errno(errno)}
+}