blob: e0b83b5c22cabf46a586d0235fa036f179b17ae9 [file] [log] [blame]
Rob Pikec80b06a2008-09-11 13:03:46 -07001// 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.
4
5package os
6
Rob Pike56069f02012-02-17 10:04:29 +11007import (
8 "errors"
9)
10
11// Portable analogs of some common system call errors.
12var (
13 ErrInvalid = errors.New("invalid argument")
14 ErrPermission = errors.New("permission denied")
15 ErrExist = errors.New("file already exists")
Anthony Martin566e0fe2012-02-18 07:44:38 +110016 ErrNotExist = errors.New("file does not exist")
Rob Pike56069f02012-02-17 10:04:29 +110017)
18
Russ Coxa0bcaf42009-06-25 20:24:55 -070019// PathError records an error and the operation and file path that caused it.
20type PathError struct {
Russ Cox08a073a2011-11-01 21:49:08 -040021 Op string
22 Path string
23 Err error
Russ Coxa0bcaf42009-06-25 20:24:55 -070024}
25
Russ Cox08a073a2011-11-01 21:49:08 -040026func (e *PathError) Error() string { return e.Op + " " + e.Path + ": " + e.Err.Error() }
Anthony Martin9f8c2c82012-02-14 14:22:34 -050027
28// SyscallError records an error from a specific system call.
29type SyscallError struct {
30 Syscall string
31 Err error
32}
33
34func (e *SyscallError) Error() string { return e.Syscall + ": " + e.Err.Error() }
35
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.
39func NewSyscallError(syscall string, err error) error {
40 if err == nil {
41 return nil
42 }
43 return &SyscallError{syscall, err}
44}