From f34e253ea3284f054f19d8a32dab969a759a5a61 Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 30 Jan 2016 12:23:56 +0100 Subject: [PATCH] Rename errors with Error prefix --- app/router/router.go | 8 +------- common/net/port_json.go | 14 +++++++------- common/net/port_json_test.go | 12 ++++++------ common/uuid/uuid.go | 6 +++--- common/uuid/uuid_test.go | 4 ++-- proxy/errors.go | 6 +++--- proxy/socks/protocol/socks.go | 2 +- proxy/socks/socks.go | 10 +++++----- proxy/vmess/protocol/vmess.go | 4 ++-- shell/point/config_json.go | 2 +- 10 files changed, 31 insertions(+), 37 deletions(-) diff --git a/app/router/router.go b/app/router/router.go index 3852959f..aaf729af 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -1,15 +1,9 @@ package router import ( - "errors" - v2net "github.com/v2ray/v2ray-core/common/net" ) -var ( - RouterNotFound = errors.New("Router not found.") -) - type Router interface { TakeDetour(v2net.Destination) (string, error) } @@ -32,5 +26,5 @@ func CreateRouter(name string, rawConfig interface{}) (Router, error) { if factory, found := routerCache[name]; found { return factory.Create(rawConfig) } - return nil, RouterNotFound + return nil, ErrorRouterNotFound } diff --git a/common/net/port_json.go b/common/net/port_json.go index 4a9c3272..c2458e27 100644 --- a/common/net/port_json.go +++ b/common/net/port_json.go @@ -13,7 +13,7 @@ import ( ) var ( - InvalidPortRange = errors.New("Invalid port range.") + ErrorInvalidPortRange = errors.New("Invalid port range.") ) func (this *PortRange) UnmarshalJSON(data []byte) error { @@ -22,7 +22,7 @@ func (this *PortRange) UnmarshalJSON(data []byte) error { if err == nil { if maybeint <= 0 || maybeint >= 65535 { log.Error("Invalid port [", serial.BytesLiteral(data), "]") - return InvalidPortRange + return ErrorInvalidPortRange } this.From = Port(maybeint) this.To = Port(maybeint) @@ -37,7 +37,7 @@ func (this *PortRange) UnmarshalJSON(data []byte) error { value, err := strconv.Atoi(pair[0]) if err != nil || value <= 0 || value >= 65535 { log.Error("Invalid from port ", pair[0]) - return InvalidPortRange + return ErrorInvalidPortRange } this.From = Port(value) this.To = Port(value) @@ -46,24 +46,24 @@ func (this *PortRange) UnmarshalJSON(data []byte) error { from, err := strconv.Atoi(pair[0]) if err != nil || from <= 0 || from >= 65535 { log.Error("Invalid from port ", pair[0]) - return InvalidPortRange + return ErrorInvalidPortRange } this.From = Port(from) to, err := strconv.Atoi(pair[1]) if err != nil || to <= 0 || to >= 65535 { log.Error("Invalid to port ", pair[1]) - return InvalidPortRange + return ErrorInvalidPortRange } this.To = Port(to) if this.From > this.To { log.Error("Invalid port range ", this.From, " -> ", this.To) - return InvalidPortRange + return ErrorInvalidPortRange } return nil } } - return InvalidPortRange + return ErrorInvalidPortRange } diff --git a/common/net/port_json_test.go b/common/net/port_json_test.go index 1f9e46bc..cf5301f7 100644 --- a/common/net/port_json_test.go +++ b/common/net/port_json_test.go @@ -27,10 +27,10 @@ func TestOverRangeIntPort(t *testing.T) { var portRange PortRange err := json.Unmarshal([]byte("70000"), &portRange) - assert.Error(err).Equals(InvalidPortRange) + assert.Error(err).Equals(ErrorInvalidPortRange) err = json.Unmarshal([]byte("-1"), &portRange) - assert.Error(err).Equals(InvalidPortRange) + assert.Error(err).Equals(ErrorInvalidPortRange) } func TestSingleStringPort(t *testing.T) { @@ -60,14 +60,14 @@ func TestOverRangeStringPort(t *testing.T) { var portRange PortRange err := json.Unmarshal([]byte("\"65536\""), &portRange) - assert.Error(err).Equals(InvalidPortRange) + assert.Error(err).Equals(ErrorInvalidPortRange) err = json.Unmarshal([]byte("\"70000-80000\""), &portRange) - assert.Error(err).Equals(InvalidPortRange) + assert.Error(err).Equals(ErrorInvalidPortRange) err = json.Unmarshal([]byte("\"1-90000\""), &portRange) - assert.Error(err).Equals(InvalidPortRange) + assert.Error(err).Equals(ErrorInvalidPortRange) err = json.Unmarshal([]byte("\"700-600\""), &portRange) - assert.Error(err).Equals(InvalidPortRange) + assert.Error(err).Equals(ErrorInvalidPortRange) } diff --git a/common/uuid/uuid.go b/common/uuid/uuid.go index f15db81f..01abec2f 100644 --- a/common/uuid/uuid.go +++ b/common/uuid/uuid.go @@ -11,7 +11,7 @@ import ( var ( byteGroups = []int{8, 4, 4, 4, 12} - InvalidID = errors.New("Invalid ID.") + ErrorInvalidID = errors.New("Invalid ID.") ) type UUID [16]byte @@ -69,7 +69,7 @@ func New() *UUID { func ParseBytes(b []byte) (*UUID, error) { if len(b) != 16 { - return nil, InvalidID + return nil, ErrorInvalidID } uuid := new(UUID) copy(uuid[:], b) @@ -79,7 +79,7 @@ func ParseBytes(b []byte) (*UUID, error) { func ParseString(str string) (*UUID, error) { text := []byte(str) if len(text) < 32 { - return nil, InvalidID + return nil, ErrorInvalidID } uuid := new(UUID) diff --git a/common/uuid/uuid_test.go b/common/uuid/uuid_test.go index a2a92c0e..55b78e26 100644 --- a/common/uuid/uuid_test.go +++ b/common/uuid/uuid_test.go @@ -19,7 +19,7 @@ func TestParseBytes(t *testing.T) { assert.String(uuid).Equals(str) uuid, err = ParseBytes([]byte{1, 3, 2, 4}) - assert.Error(err).Equals(InvalidID) + assert.Error(err).Equals(ErrorInvalidID) } func TestParseString(t *testing.T) { @@ -33,7 +33,7 @@ func TestParseString(t *testing.T) { assert.Bytes(uuid.Bytes()).Equals(expectedBytes) uuid, err = ParseString("2418d087") - assert.Error(err).Equals(InvalidID) + assert.Error(err).Equals(ErrorInvalidID) uuid, err = ParseString("2418d087-648k-4990-86e8-19dca1d006d3") assert.Error(err).IsNotNil() diff --git a/proxy/errors.go b/proxy/errors.go index 532078e3..f956419b 100644 --- a/proxy/errors.go +++ b/proxy/errors.go @@ -5,7 +5,7 @@ import ( ) var ( - InvalidAuthentication = errors.New("Invalid authentication.") - InvalidProtocolVersion = errors.New("Invalid protocol version.") - ErrorAlreadyListening = errors.New("Already listening on another port.") + ErrorInvalidAuthentication = errors.New("Invalid authentication.") + ErrorInvalidProtocolVersion = errors.New("Invalid protocol version.") + ErrorAlreadyListening = errors.New("Already listening on another port.") ) diff --git a/proxy/socks/protocol/socks.go b/proxy/socks/protocol/socks.go index 2d09453e..0212e77e 100644 --- a/proxy/socks/protocol/socks.go +++ b/proxy/socks/protocol/socks.go @@ -66,7 +66,7 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut auth.version = buffer.Value[0] if auth.version != socksVersion { log.Warning("Socks: Unknown protocol version ", auth.version) - err = proxy.InvalidProtocolVersion + err = proxy.ErrorInvalidProtocolVersion return } diff --git a/proxy/socks/socks.go b/proxy/socks/socks.go index ef9588de..9f35cb72 100644 --- a/proxy/socks/socks.go +++ b/proxy/socks/socks.go @@ -18,8 +18,8 @@ import ( ) var ( - UnsupportedSocksCommand = errors.New("Unsupported socks command.") - UnsupportedAuthMethod = errors.New("Unsupported auth method.") + ErrorUnsupportedSocksCommand = errors.New("Unsupported socks command.") + UnsupportedAuthMethod = errors.New("Unsupported auth method.") ) // SocksServer is a SOCKS 5 proxy server @@ -146,7 +146,7 @@ func (this *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.Wri } if status != byte(0) { log.Warning("Socks: Invalid user account: ", upRequest.AuthDetail()) - return proxy.InvalidAuthentication + return proxy.ErrorInvalidAuthentication } } @@ -175,7 +175,7 @@ func (this *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.Wri return err } log.Warning("Socks: Unsupported socks command ", request.Command) - return UnsupportedSocksCommand + return ErrorUnsupportedSocksCommand } response := protocol.NewSocks5Response() @@ -252,7 +252,7 @@ func (this *SocksServer) handleSocks4(reader io.Reader, writer io.Writer, auth p if result == protocol.Socks4RequestRejected { log.Warning("Socks: Unsupported socks 4 command ", auth.Command) - return UnsupportedSocksCommand + return ErrorUnsupportedSocksCommand } dest := v2net.TCPDestination(v2net.IPAddress(auth.IP[:]), auth.Port) diff --git a/proxy/vmess/protocol/vmess.go b/proxy/vmess/protocol/vmess.go index 6f608d87..11804573 100644 --- a/proxy/vmess/protocol/vmess.go +++ b/proxy/vmess/protocol/vmess.go @@ -77,7 +77,7 @@ func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { userObj, timeSec, valid := this.vUserSet.GetUser(buffer.Value[:nBytes]) if !valid { - return nil, proxy.InvalidAuthentication + return nil, proxy.ErrorInvalidAuthentication } timestampHash := TimestampHash() @@ -105,7 +105,7 @@ func (this *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { if request.Version != Version { log.Warning("VMess: Invalid protocol version ", request.Version) - return nil, proxy.InvalidProtocolVersion + return nil, proxy.ErrorInvalidProtocolVersion } request.RequestIV = append([]byte(nil), buffer.Value[1:17]...) // 16 bytes diff --git a/shell/point/config_json.go b/shell/point/config_json.go index 305ba937..fdf60bde 100644 --- a/shell/point/config_json.go +++ b/shell/point/config_json.go @@ -115,7 +115,7 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error { } if jsonConfig.PortRange == nil { log.Error("Point: Port range not specified in InboundDetour.") - return BadConfiguration + return ErrorBadConfiguration } this.Protocol = jsonConfig.Protocol this.PortRange = *jsonConfig.PortRange