-
Notifications
You must be signed in to change notification settings - Fork 53
/
error.go
40 lines (31 loc) · 959 Bytes
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package routeros
import (
"errors"
"fmt"
"github.com/go-routeros/routeros/v3/proto"
)
var (
errAlreadyAsync = errors.New("method Async() has already been called")
errAsyncLoopEnded = errors.New("method Async(): loop has ended - probably read error")
)
// UnknownReplyError records the sentence whose Word is unknown.
type UnknownReplyError struct {
Sentence *proto.Sentence
}
func (err *UnknownReplyError) Error() string {
return "unknown RouterOS reply word: " + err.Sentence.Word
}
// DeviceError records the sentence containing the error received from the device.
// The sentence may have Word !trap or !fatal.
type DeviceError struct {
Sentence *proto.Sentence
}
func (err *DeviceError) fetchMessage() string {
if m := err.Sentence.Map["message"]; m != "" {
return m
}
return "unknown error: " + err.Sentence.String()
}
func (err *DeviceError) Error() string {
return fmt.Sprintf("from RouterOS device: %s", err.fetchMessage())
}