mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-19 03:25:16 +00:00
8f8e8a9285
Also be explicit about the fact that ErrNoError is nil. That name isn't used anywhere outside this file.
38 lines
682 B
Go
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
|
|
}
|
|
}
|