77 "strconv"
88 "strings"
99
10+ "github.com/pkg/errors"
11+
1012 bit "github.com/markus-wa/demoinfocs-golang/v2/internal/bitread"
1113 common "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common"
1214 events "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
@@ -96,19 +98,19 @@ func (p *parser) parseSingleStringTable(name string) {
9698 case stNameUserInfo :
9799 player := parsePlayerInfo (bytes .NewReader (data ))
98100
99- playerIndex , err := strconv .ParseInt (stringName , 10 , 64 )
101+ playerIndex , err := strconv .Atoi (stringName )
100102 if err != nil {
101- panic ("Couldn 't parse playerIndex from string" )
103+ panic (errors . Wrap ( err , "couldn 't parse playerIndex from string") )
102104 }
103105
104106 p .rawPlayers [int (playerIndex )] = player
105107
106- p .updatePlayerFromRawIfExists (int ( playerIndex ) , player )
108+ p .updatePlayerFromRawIfExists (playerIndex , player )
107109
108110 case stNameInstanceBaseline :
109- classID , err := strconv .ParseInt (stringName , 10 , 64 )
111+ classID , err := strconv .Atoi (stringName )
110112 if err != nil {
111- panic ("Couldn 't parse id from string" )
113+ panic (errors . Wrap ( err , "couldn 't parse serverClassID from string") )
112114 }
113115
114116 p .stParser .SetInstanceBaseline (int (classID ), data )
@@ -134,8 +136,10 @@ func (p *parser) parseSingleStringTable(name string) {
134136 }
135137}
136138
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+ }()
139143
140144 cTab := p .stringTables [tab .TableId ]
141145 switch cTab .Name {
@@ -152,8 +156,10 @@ func (p *parser) handleUpdateStringTable(tab *msg.CSVCMsg_UpdateStringTable) { /
152156 }
153157}
154158
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+ }()
157163
158164 p .processStringTable (tab )
159165
@@ -164,10 +170,6 @@ func (p *parser) handleCreateStringTable(tab *msg.CSVCMsg_CreateStringTable) { /
164170
165171//nolint:funlen,gocognit
166172func (p * parser ) processStringTable (tab * msg.CSVCMsg_CreateStringTable ) {
167- defer func () {
168- p .setError (recoverFromUnexpectedEOF (recover ()))
169- }()
170-
171173 if tab .Name == stNameModelPreCache {
172174 for i := len (p .modelPreCache ); i < int (tab .MaxEntries ); i ++ {
173175 p .modelPreCache = append (p .modelPreCache , "" )
@@ -250,12 +252,12 @@ func (p *parser) processStringTable(tab *msg.CSVCMsg_CreateStringTable) {
250252 p .updatePlayerFromRawIfExists (entryIndex , player )
251253
252254 case stNameInstanceBaseline :
253- classID , err := strconv .ParseInt (entry , 10 , 64 )
255+ classID , err := strconv .Atoi (entry )
254256 if err != nil {
255- panic ("WTF VOLVO PLS" )
257+ panic (errors . Wrap ( err , "failed to parse serverClassID" ) )
256258 }
257259
258- p .stParser .SetInstanceBaseline (int ( classID ) , userdata )
260+ p .stParser .SetInstanceBaseline (classID , userdata )
259261
260262 case stNameModelPreCache :
261263 p .modelPreCache [entryIndex ] = entry
0 commit comments