2015-02-08 11:04:01 +00:00
|
|
|
// Copyright (C) 2014 The Protocol Authors.
|
|
|
|
|
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ecNoError int32 = iota
|
|
|
|
ecGeneric
|
|
|
|
ecNoSuchFile
|
|
|
|
ecInvalid
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-09-22 18:34:24 +00:00
|
|
|
ErrNoError error
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
var lookupError = map[int32]error{
|
|
|
|
ecNoError: ErrNoError,
|
|
|
|
ecGeneric: ErrGeneric,
|
|
|
|
ecNoSuchFile: ErrNoSuchFile,
|
|
|
|
ecInvalid: ErrInvalid,
|
|
|
|
}
|
|
|
|
|
|
|
|
var lookupCode = map[error]int32{
|
|
|
|
ErrNoError: ecNoError,
|
|
|
|
ErrGeneric: ecGeneric,
|
|
|
|
ErrNoSuchFile: ecNoSuchFile,
|
|
|
|
ErrInvalid: ecInvalid,
|
|
|
|
}
|
|
|
|
|
|
|
|
func codeToError(errcode int32) error {
|
|
|
|
err, ok := lookupError[errcode]
|
|
|
|
if !ok {
|
|
|
|
return ErrGeneric
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func errorToCode(err error) int32 {
|
|
|
|
code, ok := lookupCode[err]
|
|
|
|
if !ok {
|
|
|
|
return ecGeneric
|
|
|
|
}
|
|
|
|
return code
|
|
|
|
}
|