syncthing/lib/protocol/errors.go
greatroar 8f8e8a9285 lib/protocol: Simplify codeToError, errorToCode
Also be explicit about the fact that ErrNoError is nil. That name isn't
used anywhere outside this file.
2021-10-22 18:40:40 +02:00

38 lines
682 B
Go

// Copyright (C) 2014 The Protocol Authors.
package protocol
import "errors"
var (
ErrGeneric = errors.New("generic error")
ErrNoSuchFile = errors.New("no such file")
ErrInvalid = errors.New("file is invalid")
)
func codeToError(code ErrorCode) error {
switch code {
case ErrorCodeNoError:
return nil
case ErrorCodeNoSuchFile:
return ErrNoSuchFile
case ErrorCodeInvalidFile:
return ErrInvalid
default:
return ErrGeneric
}
}
func errorToCode(err error) ErrorCode {
switch err {
case nil:
return ErrorCodeNoError
case ErrNoSuchFile:
return ErrorCodeNoSuchFile
case ErrInvalid:
return ErrorCodeInvalidFile
default:
return ErrorCodeGeneric
}
}