src/pkg/os/error.go - The Go Programming Language

Golang

Source file src/pkg/os/error.go

     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.
     4	
     5	package os
     6	
     7	import (
     8		"errors"
     9	)
    10	
    11	// Portable analogs of some common system call errors.
    12	var (
    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")
    17	)
    18	
    19	// PathError records an error and the operation and file path that caused it.
    20	type PathError struct {
    21		Op   string
    22		Path string
    23		Err  error
    24	}
    25	
    26	func (e *PathError) Error() string { return e.Op + " " + e.Path + ": " + e.Err.Error() }
    27	
    28	// SyscallError records an error from a specific system call.
    29	type SyscallError struct {
    30		Syscall string
    31		Err     error
    32	}
    33	
    34	func (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.
    39	func NewSyscallError(syscall string, err error) error {
    40		if err == nil {
    41			return nil
    42		}
    43		return &SyscallError{syscall, err}
    44	}
    45	
    46	// IsExist returns whether the error is known to report that a file or directory 
    47	// already exists. It is satisfied by ErrExist as well as some syscall errors.
    48	func IsExist(err error) bool {
    49		return isExist(err)
    50	}
    51	
    52	// IsNotExist returns whether the error is known to report that a file or directory
    53	// does not exist. It is satisfied by ErrNotExist as well as some syscall errors.
    54	func IsNotExist(err error) bool {
    55		return isNotExist(err)
    56	}
    57	
    58	// IsPermission returns whether the error is known to report that permission is denied.
    59	// It is satisfied by ErrPermission as well as some syscall errors.
    60	func IsPermission(err error) bool {
    61		return isPermission(err)
    62	}