2015-02-08 11:04:01 +00:00
|
|
|
// Copyright (C) 2014 The Protocol Authors.
|
|
|
|
|
|
|
|
package protocol
|
|
|
|
|
2021-10-03 13:58:57 +00:00
|
|
|
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
|
|
|
)
|
|
|
|
|
2016-07-04 10:40:29 +00:00
|
|
|
func codeToError(code ErrorCode) error {
|
2021-10-03 13:58:57 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 10:40:29 +00:00
|
|
|
func errorToCode(err error) ErrorCode {
|
2021-10-03 13:58:57 +00:00
|
|
|
switch err {
|
|
|
|
case nil:
|
|
|
|
return ErrorCodeNoError
|
|
|
|
case ErrNoSuchFile:
|
|
|
|
return ErrorCodeNoSuchFile
|
|
|
|
case ErrInvalid:
|
|
|
|
return ErrorCodeInvalidFile
|
|
|
|
default:
|
2016-07-04 10:40:29 +00:00
|
|
|
return ErrorCodeGeneric
|
2015-02-08 11:04:01 +00:00
|
|
|
}
|
|
|
|
}
|