-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
49 lines (39 loc) · 1 KB
/
errors.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
41
42
43
44
45
46
47
48
49
// Copyright 2018 Luis Guillén Civera <luisguillenc@gmail.com>. All rights reserved.
package nfqueue
import (
"fmt"
"github.com/google/gopacket"
)
// ErrorsBuffer sets the default size for error channels
var ErrorsBuffer = 20
// ShowPacketInError if a packet digest will be show with the error string
var ShowPacketInError = false
// DumpPacketInError if a packet dump will be show with the error string
var DumpPacketInError = false
// Error is used for packet processing
type Error struct {
desc string
err error
}
// NewError creates a new packet processing error
func NewError(packet gopacket.Packet, err error) *Error {
desc := ""
if ShowPacketInError {
desc = packet.String()
}
if DumpPacketInError {
desc = packet.Dump()
}
return &Error{desc: desc, err: err}
}
// Error implements error interface
func (e *Error) Error() string {
serr := e.err.Error()
if e.desc != "" {
return fmt.Sprintf("%s: [%s]", serr, e.desc)
}
return serr
}
func (e *Error) String() string {
return e.Error()
}