syncthing/lib/protocol/errors.go

38 lines
682 B
Go
Raw Normal View History

2015-02-08 11:04:01 +00:00
// Copyright (C) 2014 The Protocol Authors.
package protocol
import "errors"
2015-02-08 11:04:01 +00:00
var (
2015-09-22 18:34:24 +00:00
ErrGeneric = errors.New("generic error")
ErrNoSuchFile = errors.New("no such file")
ErrInvalid = errors.New("file is invalid")
2015-02-08 11:04:01 +00:00
)
func codeToError(code ErrorCode) error {
switch code {
case ErrorCodeNoError:
return nil
case ErrorCodeNoSuchFile:
return ErrNoSuchFile
case ErrorCodeInvalidFile:
return ErrInvalid
default:
2015-02-08 11:04:01 +00:00
return ErrGeneric
}
}
func errorToCode(err error) ErrorCode {
switch err {
case nil:
return ErrorCodeNoError
case ErrNoSuchFile:
return ErrorCodeNoSuchFile
case ErrInvalid:
return ErrorCodeInvalidFile
default:
return ErrorCodeGeneric
2015-02-08 11:04:01 +00:00
}
}