File tree Expand file tree Collapse file tree 5 files changed +53
-5
lines changed Expand file tree Collapse file tree 5 files changed +53
-5
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ require (
9
9
github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb // indirect
10
10
github.com/markus-wa/go-unassert v0.1.1
11
11
github.com/markus-wa/gobitread v0.2.2
12
- github.com/markus-wa/godispatch v1.1.0
12
+ github.com/markus-wa/godispatch v1.2.1
13
13
github.com/markus-wa/quickhull-go/v2 v2.1.0
14
14
github.com/stretchr/objx v0.1.1 // indirect
15
15
github.com/stretchr/testify v1.5.1
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ github.com/markus-wa/gobitread v0.2.2 h1:4Z4oJ8Bf1XnOy6JZ2/9AdFKVAoxdq7awRjrb+j2
25
25
github.com/markus-wa/gobitread v0.2.2/go.mod h1:PcWXMH4gx7o2CKslbkFkLyJB/aHW7JVRG3MRZe3PINg=
26
26
github.com/markus-wa/godispatch v1.1.0 h1:J8O+hRkOCexDUQevaSKWDtKeZ3+HcmbEUKY1uYraAjY=
27
27
github.com/markus-wa/godispatch v1.1.0/go.mod h1:6o18u24oo58yseMXYD0zQFI6LbSkjJSSBQ4YyDqFX5c=
28
+ github.com/markus-wa/godispatch v1.2.0 h1:aB6epOoTbrsH3oaTE21L8/c+xiYSKOrsSDzl6YD0Xuw=
29
+ github.com/markus-wa/godispatch v1.2.0/go.mod h1:GNzV7xdnZ9+VBi0z+hma9oUQrJmtqRrqyAuGKTTTcKY=
30
+ github.com/markus-wa/godispatch v1.2.1 h1:Bj6blK4xJ/72pDi0rprVYluOGW9CV55FUDFPApyw91Q=
31
+ github.com/markus-wa/godispatch v1.2.1/go.mod h1:GNzV7xdnZ9+VBi0z+hma9oUQrJmtqRrqyAuGKTTTcKY=
28
32
github.com/markus-wa/quickhull-go/v2 v2.1.0 h1:DA2pzEzH0k5CEnlUsouRqNdD+jzNFb4DBhrX4Hpa5So=
29
33
github.com/markus-wa/quickhull-go/v2 v2.1.0/go.mod h1:bOlBUpIzGSMMhHX0f9N8CQs0VZD4nnPeta0OocH7m4o=
30
34
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Original file line number Diff line number Diff line change @@ -212,11 +212,13 @@ func (p *Parser) error() (err error) {
212
212
}
213
213
214
214
func (p *Parser) setError(err error) {
215
- if err != nil {
216
- p.errLock.Lock()
217
- p.err = err
218
- p.errLock.Unlock()
215
+ if err == nil || p.err != nil {
216
+ return
219
217
}
218
+
219
+ p.errLock.Lock()
220
+ p.err = err
221
+ p.errLock.Unlock()
220
222
}
221
223
222
224
// NewParser creates a new Parser with the default configuration.
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package demoinfocs
2
2
3
3
import (
4
4
"errors"
5
+ "fmt"
5
6
"io"
6
7
"math"
7
8
"testing"
@@ -76,3 +77,41 @@ func TestRecoverFromPanic(t *testing.T) {
76
77
assert.Equal(t, "test", recoverFromPanic("test").Error())
77
78
assert.Equal(t, "unexpected error: 1", recoverFromPanic(1).Error())
78
79
}
80
+
81
+ type consumerCodePanicMock struct {
82
+ value interface{}
83
+ }
84
+
85
+ func (ucp consumerCodePanicMock) String() string {
86
+ return fmt.Sprint(ucp.value)
87
+ }
88
+
89
+ func (ucp consumerCodePanicMock) Value() interface{} {
90
+ return ucp.value
91
+ }
92
+
93
+ func TestRecoverFromPanic_ConsumerCodePanic(t *testing.T) {
94
+ assert.PanicsWithValue(t, 1, func() {
95
+ err := recoverFromPanic(consumerCodePanicMock{value: 1})
96
+ assert.Nil(t, err)
97
+ })
98
+ }
99
+
100
+ func TestParser_SetError(t *testing.T) {
101
+ err := errors.New("test")
102
+
103
+ p := new(Parser)
104
+ p.setError(err)
105
+
106
+ assert.Same(t, err, p.error())
107
+ }
108
+
109
+ func TestParser_SetError_Multiple(t *testing.T) {
110
+ err := errors.New("test")
111
+
112
+ p := new(Parser)
113
+ p.setError(err)
114
+ p.setError(errors.New("second error"))
115
+
116
+ assert.Same(t, err, p.error())
117
+ }
Original file line number Diff line number Diff line change 9
9
10
10
"github.com/gogo/protobuf/proto"
11
11
"github.com/markus-wa/go-unassert"
12
+ dispatch "github.com/markus-wa/godispatch"
12
13
13
14
"github.com/markus-wa/demoinfocs-golang/common"
14
15
"github.com/markus-wa/demoinfocs-golang/events"
@@ -122,6 +123,8 @@ func recoverFromPanic(r interface{}) error {
122
123
}
123
124
124
125
switch err := r.(type) {
126
+ case dispatch.ConsumerCodePanic:
127
+ panic(err.Value())
125
128
case error:
126
129
return err
127
130
case string:
You can’t perform that action at this time.
0 commit comments