7
7
"strconv"
8
8
"strings"
9
9
10
+ "github.com/pkg/errors"
11
+
10
12
bit "github.com/markus-wa/demoinfocs-golang/v2/internal/bitread"
11
13
common "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common"
12
14
events "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
@@ -96,19 +98,19 @@ func (p *parser) parseSingleStringTable(name string) {
96
98
case stNameUserInfo :
97
99
player := parsePlayerInfo (bytes .NewReader (data ))
98
100
99
- playerIndex , err := strconv .ParseInt (stringName , 10 , 64 )
101
+ playerIndex , err := strconv .Atoi (stringName )
100
102
if err != nil {
101
- panic ("Couldn 't parse playerIndex from string" )
103
+ panic (errors . Wrap ( err , "couldn 't parse playerIndex from string") )
102
104
}
103
105
104
106
p .rawPlayers [int (playerIndex )] = player
105
107
106
- p .updatePlayerFromRawIfExists (int ( playerIndex ) , player )
108
+ p .updatePlayerFromRawIfExists (playerIndex , player )
107
109
108
110
case stNameInstanceBaseline :
109
- classID , err := strconv .ParseInt (stringName , 10 , 64 )
111
+ classID , err := strconv .Atoi (stringName )
110
112
if err != nil {
111
- panic ("Couldn 't parse id from string" )
113
+ panic (errors . Wrap ( err , "couldn 't parse serverClassID from string") )
112
114
}
113
115
114
116
p .stParser .SetInstanceBaseline (int (classID ), data )
@@ -134,8 +136,10 @@ func (p *parser) parseSingleStringTable(name string) {
134
136
}
135
137
}
136
138
137
- func (p * parser ) handleUpdateStringTable (tab * msg.CSVCMsg_UpdateStringTable ) { //nolint:wsl
138
- // No need for recoverFromUnexpectedEOF here as we do that in processStringTable already
139
+ func (p * parser ) handleUpdateStringTable (tab * msg.CSVCMsg_UpdateStringTable ) {
140
+ defer func () {
141
+ p .setError (recoverFromUnexpectedEOF (recover ()))
142
+ }()
139
143
140
144
cTab := p .stringTables [tab .TableId ]
141
145
switch cTab .Name {
@@ -152,8 +156,10 @@ func (p *parser) handleUpdateStringTable(tab *msg.CSVCMsg_UpdateStringTable) { /
152
156
}
153
157
}
154
158
155
- func (p * parser ) handleCreateStringTable (tab * msg.CSVCMsg_CreateStringTable ) { //nolint:wsl
156
- // No need for recoverFromUnexpectedEOF here as we do that in processStringTable already
159
+ func (p * parser ) handleCreateStringTable (tab * msg.CSVCMsg_CreateStringTable ) {
160
+ defer func () {
161
+ p .setError (recoverFromUnexpectedEOF (recover ()))
162
+ }()
157
163
158
164
p .processStringTable (tab )
159
165
@@ -164,10 +170,6 @@ func (p *parser) handleCreateStringTable(tab *msg.CSVCMsg_CreateStringTable) { /
164
170
165
171
//nolint:funlen,gocognit
166
172
func (p * parser ) processStringTable (tab * msg.CSVCMsg_CreateStringTable ) {
167
- defer func () {
168
- p .setError (recoverFromUnexpectedEOF (recover ()))
169
- }()
170
-
171
173
if tab .Name == stNameModelPreCache {
172
174
for i := len (p .modelPreCache ); i < int (tab .MaxEntries ); i ++ {
173
175
p .modelPreCache = append (p .modelPreCache , "" )
@@ -250,12 +252,12 @@ func (p *parser) processStringTable(tab *msg.CSVCMsg_CreateStringTable) {
250
252
p .updatePlayerFromRawIfExists (entryIndex , player )
251
253
252
254
case stNameInstanceBaseline :
253
- classID , err := strconv .ParseInt (entry , 10 , 64 )
255
+ classID , err := strconv .Atoi (entry )
254
256
if err != nil {
255
- panic ("WTF VOLVO PLS" )
257
+ panic (errors . Wrap ( err , "failed to parse serverClassID" ) )
256
258
}
257
259
258
- p .stParser .SetInstanceBaseline (int ( classID ) , userdata )
260
+ p .stParser .SetInstanceBaseline (classID , userdata )
259
261
260
262
case stNameModelPreCache :
261
263
p .modelPreCache [entryIndex ] = entry
0 commit comments