Skip to content

Commit be93db4

Browse files
committed
core: don't suppress ConsumerCodePanic in recoverFromPanic
1 parent 6d793e4 commit be93db4

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ github.com/markus-wa/gobitread v0.2.2 h1:4Z4oJ8Bf1XnOy6JZ2/9AdFKVAoxdq7awRjrb+j2
2525
github.com/markus-wa/gobitread v0.2.2/go.mod h1:PcWXMH4gx7o2CKslbkFkLyJB/aHW7JVRG3MRZe3PINg=
2626
github.com/markus-wa/godispatch v1.1.0 h1:J8O+hRkOCexDUQevaSKWDtKeZ3+HcmbEUKY1uYraAjY=
2727
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=
2832
github.com/markus-wa/quickhull-go/v2 v2.1.0 h1:DA2pzEzH0k5CEnlUsouRqNdD+jzNFb4DBhrX4Hpa5So=
2933
github.com/markus-wa/quickhull-go/v2 v2.1.0/go.mod h1:bOlBUpIzGSMMhHX0f9N8CQs0VZD4nnPeta0OocH7m4o=
3034
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

parser.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,13 @@ func (p *Parser) error() (err error) {
212212
}
213213

214214
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
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.

parser_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package demoinfocs
22

33
import (
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+
}

parsing.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
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:

0 commit comments

Comments
 (0)