Skip to content

Commit

Permalink
cleanup error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Apr 9, 2017
1 parent 0e01e9e commit 68bc9ea
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 78 deletions.
6 changes: 3 additions & 3 deletions app/router/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (v *RoutingRule) BuildCondition() (Condition, error) {
}
ipv6Cond.Add(matcher)
default:
return nil, newError("Router: Invalid IP length.")
return nil, newError("invalid IP length").AtError()
}
}

Expand Down Expand Up @@ -93,7 +93,7 @@ func (v *RoutingRule) BuildCondition() (Condition, error) {
}
ipv6Cond.Add(matcher)
default:
return nil, newError("Router: Invalid IP length.")
return nil, newError("invalid IP length").AtError()
}
}

Expand All @@ -118,7 +118,7 @@ func (v *RoutingRule) BuildCondition() (Condition, error) {
}

if conds.Len() == 0 {
return nil, newError("Router: This rule has no effective fields.")
return nil, newError("this rule has no effective fields").AtError()
}

return conds, nil
Expand Down
4 changes: 2 additions & 2 deletions app/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Router struct {
func NewRouter(ctx context.Context, config *Config) (*Router, error) {
space := app.SpaceFromContext(ctx)
if space == nil {
return nil, newError("Router: No space in context.")
return nil, newError("no space in context")
}
r := &Router{
domainStrategy: config.DomainStrategy,
Expand All @@ -45,7 +45,7 @@ func NewRouter(ctx context.Context, config *Config) (*Router, error) {

r.dnsServer = dns.FromSpace(space)
if r.dnsServer == nil {
return newError("Router: DNS is not found in the space.")
return newError("DNS is not found in the space")
}
return nil
})
Expand Down
6 changes: 3 additions & 3 deletions app/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func CreateAppFromConfig(ctx context.Context, config interface{}) (Application,
case Application:
return a, nil
default:
return nil, newError("App: Not an application.")
return nil, newError("not an application")
}
}

Expand Down Expand Up @@ -81,7 +81,7 @@ func (v *spaceImpl) GetApplication(appInterface interface{}) Application {

func (v *spaceImpl) AddApplication(app Application) error {
if v == nil {
return newError("App: Nil space.")
return newError("nil space").AtError()
}
appType := reflect.TypeOf(app.Interface())
v.cache[appType] = app
Expand Down Expand Up @@ -112,7 +112,7 @@ const (
func AddApplicationToSpace(ctx context.Context, appConfig interface{}) error {
space := SpaceFromContext(ctx)
if space == nil {
return newError("App: No space in context.")
return newError("no space in context").AtError()
}
application, err := CreateAppFromConfig(ctx, appConfig)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion common/buf/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Reader interface {
Read() (*Buffer, error)
}

var ErrReadTimeout = newError("Buf: IO timeout.")
var ErrReadTimeout = newError("IO timeout")

type TimeoutReader interface {
ReadTimeout(time.Duration) (*Buffer, error)
Expand Down
4 changes: 2 additions & 2 deletions common/crypto/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type AEADAuthenticator struct {
func (v *AEADAuthenticator) Open(dst, cipherText []byte) ([]byte, error) {
iv := v.NonceGenerator.Next()
if len(iv) != v.AEAD.NonceSize() {
return nil, newError("Crypto:AEADAuthenticator: Invalid nonce size: ", len(iv))
return nil, newError("invalid AEAD nonce size: ", len(iv))
}

additionalData := v.AdditionalDataGenerator.Next()
Expand All @@ -61,7 +61,7 @@ func (v *AEADAuthenticator) Open(dst, cipherText []byte) ([]byte, error) {
func (v *AEADAuthenticator) Seal(dst, plainText []byte) ([]byte, error) {
iv := v.NonceGenerator.Next()
if len(iv) != v.AEAD.NonceSize() {
return nil, newError("Crypto:AEADAuthenticator: Invalid nonce size: ", len(iv))
return nil, newError("invalid AEAD nonce size: ", len(iv))
}

additionalData := v.AdditionalDataGenerator.Next()
Expand Down
2 changes: 1 addition & 1 deletion common/net/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func IPAddress(ip []byte) Address {
}
return addr
default:
log.Trace(newError("Net: Invalid IP format: ", ip).AtError())
log.Trace(newError("invalid IP format: ", ip).AtError())
return nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/net/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func PortFromBytes(port []byte) Port {
// @error when the integer is not positive or larger then 65535
func PortFromInt(val uint32) (Port, error) {
if val > 65535 {
return Port(0), newError("Net: Invalid port range: ", val)
return Port(0), newError("invalid port range: ", val)
}
return Port(val), nil
}
Expand All @@ -29,7 +29,7 @@ func PortFromInt(val uint32) (Port, error) {
func PortFromString(s string) (Port, error) {
val, err := strconv.ParseUint(s, 10, 32)
if err != nil {
return Port(0), newError("Net: Invalid port range: ", s)
return Port(0), newError("invalid port range: ", s)
}
return PortFromInt(uint32(val))
}
Expand Down
4 changes: 2 additions & 2 deletions common/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
func RegisterConfig(config interface{}, configCreator ConfigCreator) error {
configType := reflect.TypeOf(config)
if _, found := typeCreatorRegistry[configType]; found {
return newError("Common: " + configType.Name() + " is already registered.")
return newError(configType.Name() + " is already registered").AtError()
}
typeCreatorRegistry[configType] = configCreator
return nil
Expand All @@ -27,7 +27,7 @@ func CreateObject(ctx context.Context, config interface{}) (interface{}, error)
configType := reflect.TypeOf(config)
creator, found := typeCreatorRegistry[configType]
if !found {
return nil, newError("Common: " + configType.String() + " is not registered.")
return nil, newError(configType.String() + " is not registered").AtError()
}
return creator(ctx, config)
}
6 changes: 3 additions & 3 deletions proxy/dokodemo/dokodemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type DokodemoDoor struct {
func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
space := app.SpaceFromContext(ctx)
if space == nil {
return nil, newError("Dokodemo: No space in context.")
return nil, newError("no space in context")
}
if config.NetworkList == nil || config.NetworkList.Size() == 0 {
return nil, newError("DokodemoDoor: No network specified.")
return nil, newError("no network specified")
}
d := &DokodemoDoor{
config: config,
Expand All @@ -45,7 +45,7 @@ func (d *DokodemoDoor) Network() net.NetworkList {
}

func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher dispatcher.Interface) error {
log.Trace(newError("Dokodemo: processing connection from: ", conn.RemoteAddr()).AtDebug())
log.Trace(newError("processing connection from: ", conn.RemoteAddr()).AtDebug())
dest := net.Destination{
Network: network,
Address: d.address,
Expand Down
4 changes: 2 additions & 2 deletions proxy/handler_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func CreateInboundHandler(ctx context.Context, config interface{}) (Inbound, err
case Inbound:
return h, nil
default:
return nil, newError("Proxy: Not a InboundHandler.")
return nil, newError("not a InboundHandler")
}
}

Expand All @@ -28,6 +28,6 @@ func CreateOutboundHandler(ctx context.Context, config interface{}) (Outbound, e
case Outbound:
return h, nil
default:
return nil, newError("Proxy: Not a OutboundHandler.")
return nil, newError("not a OutboundHandler")
}
}
8 changes: 4 additions & 4 deletions tools/conf/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (v *StringList) UnmarshalJSON(data []byte) error {
*v = *NewStringList(strlist)
return nil
}
return newError("Config: Unknown format of a string list: " + string(data))
return newError("unknown format of a string list: " + string(data))
}

type Address struct {
Expand Down Expand Up @@ -79,7 +79,7 @@ func (v *NetworkList) UnmarshalJSON(data []byte) error {
*v = nl
return nil
}
return newError("Config: Unknown format of a string list: " + string(data))
return newError("unknown format of a string list: " + string(data))
}

func (v *NetworkList) Build() *v2net.NetworkList {
Expand Down Expand Up @@ -157,12 +157,12 @@ func (v *PortRange) UnmarshalJSON(data []byte) error {
v.From = uint32(from)
v.To = uint32(to)
if v.From > v.To {
return newError("Config: Invalid port range ", v.From, " -> ", v.To)
return newError("invalid port range ", v.From, " -> ", v.To)
}
return nil
}

return newError("Config: Invalid port range: ", string(data))
return newError("invalid port range: ", string(data))
}

type User struct {
Expand Down
4 changes: 2 additions & 2 deletions tools/conf/freedom.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func (v *FreedomConfig) Build() (*serial.TypedMessage, error) {
if len(v.Redirect) > 0 {
host, portStr, err := net.SplitHostPort(v.Redirect)
if err != nil {
return nil, newError("Config: Invalid redirect address: ", v.Redirect, ": ", err).Base(err)
return nil, newError("invalid redirect address: ", v.Redirect, ": ", err).Base(err)
}
port, err := v2net.PortFromString(portStr)
if err != nil {
return nil, newError("Config: Invalid redirect port: ", v.Redirect, ": ", err).Base(err)
return nil, newError("invalid redirect port: ", v.Redirect, ": ", err).Base(err)
}
if len(host) == 0 {
host = "127.0.0.1"
Expand Down
10 changes: 5 additions & 5 deletions tools/conf/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type ConfigCreatorCache map[string]ConfigCreator

func (v ConfigCreatorCache) RegisterCreator(id string, creator ConfigCreator) error {
if _, found := v[id]; found {
return newError("Config: ", id, " already registered.")
return newError(id, " already registered.").AtError()
}

v[id] = creator
Expand All @@ -18,7 +18,7 @@ func (v ConfigCreatorCache) RegisterCreator(id string, creator ConfigCreator) er
func (v ConfigCreatorCache) CreateConfig(id string) (interface{}, error) {
creator, found := v[id]
if !found {
return nil, newError("Config: Unknown config id: ", id)
return nil, newError("unknown config id: ", id)
}
return creator(), nil
}
Expand All @@ -40,7 +40,7 @@ func NewJSONConfigLoader(cache ConfigCreatorCache, idKey string, configKey strin
func (v *JSONConfigLoader) LoadWithID(raw []byte, id string) (interface{}, error) {
creator, found := v.cache[id]
if !found {
return nil, newError("Config: Unknown config id: ", id)
return nil, newError("unknown config id: ", id).AtError()
}

config := creator()
Expand All @@ -57,7 +57,7 @@ func (v *JSONConfigLoader) Load(raw []byte) (interface{}, string, error) {
}
rawID, found := obj[v.idKey]
if !found {
return nil, "", newError("Config: ", v.idKey, " not found in JSON context.")
return nil, "", newError(v.idKey, " not found in JSON context").AtError()
}
var id string
if err := json.Unmarshal(rawID, &id); err != nil {
Expand All @@ -67,7 +67,7 @@ func (v *JSONConfigLoader) Load(raw []byte) (interface{}, string, error) {
if len(v.configKey) > 0 {
configValue, found := obj[v.configKey]
if !found {
return nil, "", newError("Config: ", v.configKey, " not found in JSON content.")
return nil, "", newError(v.configKey, " not found in JSON content").AtError()
}
rawConfig = configValue
}
Expand Down
4 changes: 2 additions & 2 deletions tools/conf/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (v *ShadowsocksServerConfig) Build() (*serial.TypedMessage, error) {
case "chacha20-ietf":
account.CipherType = shadowsocks.CipherType_CHACHA20_IETF
default:
return nil, newError("Unknown cipher method: " + cipher)
return nil, newError("unknown cipher method: " + cipher)
}

config.User = &protocol.User{
Expand Down Expand Up @@ -107,7 +107,7 @@ func (v *ShadowsocksClientConfig) Build() (*serial.TypedMessage, error) {
case "chacha20-ietf":
account.CipherType = shadowsocks.CipherType_CHACHA20_IETF
default:
return nil, newError("Unknown cipher method: " + cipher)
return nil, newError("unknown cipher method: " + cipher)
}

ss := &protocol.ServerEndpoint{
Expand Down
6 changes: 3 additions & 3 deletions tools/conf/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (v *SocksServerConfig) Build() (*serial.TypedMessage, error) {
} else if v.AuthMethod == AuthMethodUserPass {
config.AuthType = socks.AuthType_PASSWORD
} else {
return nil, newError("Config: Unknown socks auth method: " + v.AuthMethod)
return nil, newError("unknown socks auth method: " + v.AuthMethod).AtError()
}

if len(v.Accounts) > 0 {
Expand Down Expand Up @@ -79,11 +79,11 @@ func (v *SocksClientConfig) Build() (*serial.TypedMessage, error) {
for _, rawUser := range serverConfig.Users {
user := new(protocol.User)
if err := json.Unmarshal(rawUser, user); err != nil {
return nil, newError("Config: Failed to parse Socks user.").Base(err)
return nil, newError("failed to parse Socks user").Base(err).AtError()
}
account := new(SocksAccount)
if err := json.Unmarshal(rawUser, account); err != nil {
return nil, newError("Config: Failed to parse socks account.").Base(err)
return nil, newError("failed to parse socks account").Base(err).AtError()
}
user.Account = serial.ToTypedMessage(account.Build())
server.User = append(server.User, user)
Expand Down
6 changes: 3 additions & 3 deletions tools/conf/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
if v.TCPConfig != nil {
ts, err := v.TCPConfig.Build()
if err != nil {
return nil, newError("Config: Failed to build TCP config.").Base(err)
return nil, newError("failed to build TCP config").Base(err).AtError()
}
config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{
Protocol: internet.TransportProtocol_TCP,
Expand All @@ -28,7 +28,7 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
if v.KCPConfig != nil {
ts, err := v.KCPConfig.Build()
if err != nil {
return nil, newError("Config: Failed to build mKCP config.").Base(err)
return nil, newError("failed to build mKCP config").Base(err).AtError()
}
config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{
Protocol: internet.TransportProtocol_MKCP,
Expand All @@ -39,7 +39,7 @@ func (v *TransportConfig) Build() (*transport.Config, error) {
if v.WSConfig != nil {
ts, err := v.WSConfig.Build()
if err != nil {
return nil, newError("Config: Failed to build WebSocket config.").Base(err)
return nil, newError("failed to build WebSocket config").Base(err)
}
config.TransportSettings = append(config.TransportSettings, &internet.TransportConfig{
Protocol: internet.TransportProtocol_WebSocket,
Expand Down
4 changes: 2 additions & 2 deletions tools/conf/transport_authenticators.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (v *HTTPAuthenticatorRequest) Build() (*http.RequestConfig, error) {
config.Header = make([]*http.Header, 0, len(v.Headers))
for key, value := range v.Headers {
if value == nil {
return nil, newError("Config: Empty HTTP header value: " + key)
return nil, newError("empty HTTP header value: " + key).AtError()
}
config.Header = append(config.Header, &http.Header{
Name: key,
Expand Down Expand Up @@ -158,7 +158,7 @@ func (v *HTTPAuthenticatorResponse) Build() (*http.ResponseConfig, error) {
config.Header = make([]*http.Header, 0, len(v.Headers))
for key, value := range v.Headers {
if value == nil {
return nil, newError("Config: Empty HTTP header value: " + key)
return nil, newError("empty HTTP header value: " + key).AtError()
}
config.Header = append(config.Header, &http.Header{
Name: key,
Expand Down
Loading

0 comments on commit 68bc9ea

Please sign in to comment.