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 (
99 github.com/llgcode/ps v0.0.0-20150911083025-f1443b32eedb // indirect
1010 github.com/markus-wa/go-unassert v0.1.1
1111 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
1313 github.com/markus-wa/quickhull-go/v2 v2.1.0
1414 github.com/stretchr/objx v0.1.1 // indirect
1515 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
2525github.com/markus-wa/gobitread v0.2.2 /go.mod h1:PcWXMH4gx7o2CKslbkFkLyJB/aHW7JVRG3MRZe3PINg =
2626github.com/markus-wa/godispatch v1.1.0 h1:J8O+hRkOCexDUQevaSKWDtKeZ3+HcmbEUKY1uYraAjY =
2727github.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 =
2832github.com/markus-wa/quickhull-go/v2 v2.1.0 h1:DA2pzEzH0k5CEnlUsouRqNdD+jzNFb4DBhrX4Hpa5So =
2933github.com/markus-wa/quickhull-go/v2 v2.1.0 /go.mod h1:bOlBUpIzGSMMhHX0f9N8CQs0VZD4nnPeta0OocH7m4o =
3034github.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) {
212212}
213213
214214func (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
219217 }
218+
219+ p .errLock .Lock ()
220+ p .err = err
221+ p .errLock .Unlock ()
220222}
221223
222224// 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
22
33import (
44 "errors"
5+ "fmt"
56 "io"
67 "math"
78 "testing"
@@ -76,3 +77,41 @@ func TestRecoverFromPanic(t *testing.T) {
7677 assert .Equal (t , "test" , recoverFromPanic ("test" ).Error ())
7778 assert .Equal (t , "unexpected error: 1" , recoverFromPanic (1 ).Error ())
7879}
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 99
1010 "github.com/gogo/protobuf/proto"
1111 "github.com/markus-wa/go-unassert"
12+ dispatch "github.com/markus-wa/godispatch"
1213
1314 "github.com/markus-wa/demoinfocs-golang/common"
1415 "github.com/markus-wa/demoinfocs-golang/events"
@@ -122,6 +123,8 @@ func recoverFromPanic(r interface{}) error {
122123 }
123124
124125 switch err := r .(type ) {
126+ case dispatch.ConsumerCodePanic :
127+ panic (err .Value ())
125128 case error :
126129 return err
127130 case string :
You can’t perform that action at this time.
0 commit comments