syncthing/lib/protocol/errors.go

45 lines
862 B
Go
Raw Permalink Normal View History

2015-02-08 11:04:01 +00:00
// Copyright (C) 2014 The Protocol Authors.
package protocol
import (
"errors"
)
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[ErrorCode]error{
ErrorCodeNoError: ErrNoError,
ErrorCodeGeneric: ErrGeneric,
ErrorCodeNoSuchFile: ErrNoSuchFile,
ErrorCodeInvalidFile: ErrInvalid,
2015-02-08 11:04:01 +00:00
}
var lookupCode = map[error]ErrorCode{
ErrNoError: ErrorCodeNoError,
ErrGeneric: ErrorCodeGeneric,
ErrNoSuchFile: ErrorCodeNoSuchFile,
ErrInvalid: ErrorCodeInvalidFile,
2015-02-08 11:04:01 +00:00
}
func codeToError(code ErrorCode) error {
err, ok := lookupError[code]
2015-02-08 11:04:01 +00:00
if !ok {
return ErrGeneric
}
return err
}
func errorToCode(err error) ErrorCode {
2015-02-08 11:04:01 +00:00
code, ok := lookupCode[err]
if !ok {
return ErrorCodeGeneric
2015-02-08 11:04:01 +00:00
}
return code
}