error hint
This commit is contained in:
parent
ed15f041ce
commit
ef798c1ac7
11
errors.go
Normal file
11
errors.go
Normal file
@ -0,0 +1,11 @@
|
||||
package tunnel
|
||||
|
||||
import "fmt"
|
||||
|
||||
type WrongDataFrameTypeError struct {
|
||||
ShouldBe Type
|
||||
}
|
||||
|
||||
func (w WrongDataFrameTypeError) Error() string {
|
||||
return fmt.Sprintf("wrong dataframe type, should be %s(%d)", w.ShouldBe, w.ShouldBe)
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package tunnel
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
@ -84,8 +83,7 @@ func (m *Manager) Connect() (*Connection, error) {
|
||||
|
||||
df = <-connection.RX
|
||||
if df.Type != TypeConnected {
|
||||
|
||||
return nil, errors.New("failed to connect")
|
||||
return nil, WrongDataFrameTypeError{ShouldBe: TypeConnected}
|
||||
}
|
||||
return connection, nil
|
||||
}
|
||||
@ -93,7 +91,7 @@ func (m *Manager) Connect() (*Connection, error) {
|
||||
func (m *Manager) Accept() (*Connection, error) {
|
||||
df := <-m.accept
|
||||
if df.Type != TypeRequest {
|
||||
return nil, errors.New("failed to accept")
|
||||
return nil, WrongDataFrameTypeError{ShouldBe: TypeRequest}
|
||||
}
|
||||
connection := &Connection{
|
||||
ID: df.ID,
|
||||
|
14
types.go
14
types.go
@ -9,3 +9,17 @@ func NewID() ID {
|
||||
}
|
||||
|
||||
type Type uint8
|
||||
|
||||
func (t Type) String() string {
|
||||
switch t {
|
||||
case TypeNormal:
|
||||
return "normal"
|
||||
case TypeRequest:
|
||||
return "request"
|
||||
case TypeConnected:
|
||||
return "connected"
|
||||
case TypeClosed:
|
||||
return "closed"
|
||||
}
|
||||
return "invalid"
|
||||
}
|
||||
|
Reference in New Issue
Block a user