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
|
package tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -84,8 +83,7 @@ func (m *Manager) Connect() (*Connection, error) {
|
|||||||
|
|
||||||
df = <-connection.RX
|
df = <-connection.RX
|
||||||
if df.Type != TypeConnected {
|
if df.Type != TypeConnected {
|
||||||
|
return nil, WrongDataFrameTypeError{ShouldBe: TypeConnected}
|
||||||
return nil, errors.New("failed to connect")
|
|
||||||
}
|
}
|
||||||
return connection, nil
|
return connection, nil
|
||||||
}
|
}
|
||||||
@ -93,7 +91,7 @@ func (m *Manager) Connect() (*Connection, error) {
|
|||||||
func (m *Manager) Accept() (*Connection, error) {
|
func (m *Manager) Accept() (*Connection, error) {
|
||||||
df := <-m.accept
|
df := <-m.accept
|
||||||
if df.Type != TypeRequest {
|
if df.Type != TypeRequest {
|
||||||
return nil, errors.New("failed to accept")
|
return nil, WrongDataFrameTypeError{ShouldBe: TypeRequest}
|
||||||
}
|
}
|
||||||
connection := &Connection{
|
connection := &Connection{
|
||||||
ID: df.ID,
|
ID: df.ID,
|
||||||
|
Reference in New Issue
Block a user