@@ -442,7 +442,7 @@ func (conn *Conn) Flush() error {
442
442
if len (conn .bufferedSend ) > 0 {
443
443
if err := conn .enc .Encode (conn .bufferedSend ); err != nil && ! errors .Is (err , net .ErrClosed ) {
444
444
// Should never happen.
445
- panic (fmt .Errorf ("error encoding packet batch: %v " , err ))
445
+ panic (fmt .Errorf ("error encoding packet batch: %w " , err ))
446
446
}
447
447
// First manually clear out conn.bufferedSend so that re-using the slice after resetting its length to
448
448
// 0 doesn't result in an 'invisible' memory leak.
@@ -612,7 +612,7 @@ func (conn *Conn) handleMultiple(pks []packet.Packet) error {
612
612
var err error
613
613
for _ , pk := range pks {
614
614
if e := conn .handlePacket (pk ); e != nil {
615
- err = e
615
+ err = fmt . Errorf ( "handle %T: %w" , pk , e )
616
616
}
617
617
}
618
618
return err
@@ -685,15 +685,15 @@ func (conn *Conn) handleRequestNetworkSettings(pk *packet.RequestNetworkSettings
685
685
status = packet .PlayStatusLoginFailedServer
686
686
}
687
687
_ = conn .WritePacket (& packet.PlayStatus {Status : status })
688
- return fmt .Errorf ("%v connected with an incompatible protocol: expected protocol = %v, client protocol = %v" , conn . identityData . DisplayName , protocol .CurrentProtocol , pk .ClientProtocol )
688
+ return fmt .Errorf ("incompatible protocol version : expected %v, got %v" , protocol .CurrentProtocol , pk .ClientProtocol )
689
689
}
690
690
691
691
conn .expect (packet .IDLogin )
692
692
if err := conn .WritePacket (& packet.NetworkSettings {
693
693
CompressionThreshold : 512 ,
694
694
CompressionAlgorithm : conn .compression .EncodeCompression (),
695
695
}); err != nil {
696
- return fmt .Errorf ("error sending network settings : %v " , err )
696
+ return fmt .Errorf ("send NetworkSettings : %w " , err )
697
697
}
698
698
_ = conn .Flush ()
699
699
conn .enc .EnableCompression (conn .compression )
@@ -705,7 +705,7 @@ func (conn *Conn) handleRequestNetworkSettings(pk *packet.RequestNetworkSettings
705
705
func (conn * Conn ) handleNetworkSettings (pk * packet.NetworkSettings ) error {
706
706
alg , ok := packet .CompressionByID (pk .CompressionAlgorithm )
707
707
if ! ok {
708
- return fmt .Errorf ("unknown compression algorithm: %v" , pk .CompressionAlgorithm )
708
+ return fmt .Errorf ("unknown compression algorithm %v" , pk .CompressionAlgorithm )
709
709
}
710
710
conn .enc .EnableCompression (alg )
711
711
conn .dec .EnableCompression ()
@@ -730,10 +730,10 @@ func (conn *Conn) handleLogin(pk *packet.Login) error {
730
730
// Make sure the player is logged in with XBOX Live when necessary.
731
731
if ! authResult .XBOXLiveAuthenticated && conn .authEnabled {
732
732
_ = conn .WritePacket (& packet.Disconnect {Message : text .Colourf ("<red>You must be logged in with XBOX Live to join.</red>" )})
733
- return fmt .Errorf ("connection %v was not authenticated to XBOX Live" , conn . RemoteAddr () )
733
+ return fmt .Errorf ("client was not authenticated to XBOX Live" )
734
734
}
735
735
if err := conn .enableEncryption (authResult .PublicKey ); err != nil {
736
- return fmt .Errorf ("error enabling encryption: %v " , err )
736
+ return fmt .Errorf ("enable encryption: %w " , err )
737
737
}
738
738
return nil
739
739
}
@@ -743,7 +743,7 @@ func (conn *Conn) handleClientToServerHandshake() error {
743
743
// The next expected packet is a resource pack client response.
744
744
conn .expect (packet .IDResourcePackClientResponse , packet .IDClientCacheStatus )
745
745
if err := conn .WritePacket (& packet.PlayStatus {Status : packet .PlayStatusLoginSuccess }); err != nil {
746
- return fmt .Errorf ("error sending play status login success : %v " , err )
746
+ return fmt .Errorf ("send PlayStatus (Status=LoginSuccess) : %w " , err )
747
747
}
748
748
pk := & packet.ResourcePacksInfo {TexturePackRequired : conn .texturePacksRequired }
749
749
for _ , pack := range conn .resourcePacks {
@@ -775,7 +775,7 @@ func (conn *Conn) handleClientToServerHandshake() error {
775
775
}
776
776
// Finally we send the packet after the play status.
777
777
if err := conn .WritePacket (pk ); err != nil {
778
- return fmt .Errorf ("error sending resource packs info : %v " , err )
778
+ return fmt .Errorf ("send ResourcePacksInfo : %w " , err )
779
779
}
780
780
return nil
781
781
}
@@ -809,7 +809,7 @@ func (conn *Conn) handleServerToClientHandshake(pk *packet.ServerToClientHandsha
809
809
c .Salt = strings .TrimRight (c .Salt , "=" )
810
810
salt , err := base64 .RawStdEncoding .DecodeString (c .Salt )
811
811
if err != nil {
812
- return fmt .Errorf ("error base64 decoding ServerToClientHandshake salt: %v " , err )
812
+ return fmt .Errorf ("decode ServerToClientHandshake salt: %w " , err )
813
813
}
814
814
815
815
x , _ := pub .Curve .ScalarMult (pub .X , pub .Y , conn .privateKey .D .Bytes ())
@@ -849,7 +849,7 @@ func (conn *Conn) handleResourcePacksInfo(pk *packet.ResourcePacksInfo) error {
849
849
850
850
for index , pack := range pk .TexturePacks {
851
851
if _ , ok := conn .packQueue .downloadingPacks [pack .UUID ]; ok {
852
- conn .log .Printf ("duplicate texture pack entry %v in resource pack info \n " , pack .UUID )
852
+ conn .log .Printf ("handle ResourcePacksInfo: duplicate texture pack (UUID=%v) \n " , pack .UUID )
853
853
conn .packQueue .packAmount --
854
854
continue
855
855
}
@@ -872,7 +872,7 @@ func (conn *Conn) handleResourcePacksInfo(pk *packet.ResourcePacksInfo) error {
872
872
}
873
873
for index , pack := range pk .BehaviourPacks {
874
874
if _ , ok := conn .packQueue .downloadingPacks [pack .UUID ]; ok {
875
- conn .log .Printf ("duplicate behaviour pack entry %v in resource pack info \n " , pack .UUID )
875
+ conn .log .Printf ("handle ResourcePacksInfo: duplicate behaviour pack (UUID=%v) \n " , pack .UUID )
876
876
conn .packQueue .packAmount --
877
877
continue
878
878
}
@@ -918,17 +918,17 @@ func (conn *Conn) handleResourcePackStack(pk *packet.ResourcePackStack) error {
918
918
if pack .UUID == behaviourPack .UUID {
919
919
// We had a behaviour pack with the same UUID as the texture pack, so we drop the texture
920
920
// pack and log it.
921
- conn .log .Printf ("dropping behaviour pack with UUID %v due to a texture pack with the same UUID\n " , pack .UUID )
921
+ conn .log .Printf ("handle ResourcePackStack: dropping behaviour pack ( UUID=%v) due to a texture pack with the same UUID\n " , pack .UUID )
922
922
pk .BehaviourPacks = append (pk .BehaviourPacks [:i ], pk .BehaviourPacks [i + 1 :]... )
923
923
}
924
924
}
925
925
if ! conn .hasPack (pack .UUID , pack .Version , false ) {
926
- return fmt .Errorf ("texture pack {uuid =%v, version=%v} not downloaded" , pack .UUID , pack .Version )
926
+ return fmt .Errorf ("texture pack (UUID =%v, version=%v) not downloaded" , pack .UUID , pack .Version )
927
927
}
928
928
}
929
929
for _ , pack := range pk .BehaviourPacks {
930
930
if ! conn .hasPack (pack .UUID , pack .Version , true ) {
931
- return fmt .Errorf ("behaviour pack {uuid =%v, version=%v} not downloaded" , pack .UUID , pack .Version )
931
+ return fmt .Errorf ("behaviour pack (UUID =%v, version=%v) not downloaded" , pack .UUID , pack .Version )
932
932
}
933
933
}
934
934
conn .expect (packet .IDStartGame )
@@ -977,7 +977,7 @@ func (conn *Conn) handleResourcePackClientResponse(pk *packet.ResourcePackClient
977
977
packs := pk .PacksToDownload
978
978
conn .packQueue = & resourcePackQueue {packs : conn .resourcePacks }
979
979
if err := conn .packQueue .Request (packs ); err != nil {
980
- return fmt .Errorf ("error looking up resource packs to download : %v " , err )
980
+ return fmt .Errorf ("lookup resource packs by UUID : %w " , err )
981
981
}
982
982
// Proceed with the first resource pack download. We run all downloads in sequence rather than in
983
983
// parallel, as it's less prone to packet loss.
@@ -1003,12 +1003,12 @@ func (conn *Conn) handleResourcePackClientResponse(pk *packet.ResourcePackClient
1003
1003
})
1004
1004
}
1005
1005
if err := conn .WritePacket (pk ); err != nil {
1006
- return fmt .Errorf ("error writing resource pack stack packet : %v " , err )
1006
+ return fmt .Errorf ("send ResourcePackStack : %w " , err )
1007
1007
}
1008
1008
case packet .PackResponseCompleted :
1009
1009
conn .loggedIn = true
1010
1010
default :
1011
- return fmt .Errorf ("unknown resource pack client response: %v" , pk .Response )
1011
+ return fmt .Errorf ("unknown ResourcePackClientResponse response type %v" , pk .Response )
1012
1012
}
1013
1013
return nil
1014
1014
}
@@ -1069,7 +1069,7 @@ func (conn *Conn) nextResourcePackDownload() error {
1069
1069
return fmt .Errorf ("no resource packs to download" )
1070
1070
}
1071
1071
if err := conn .WritePacket (pk ); err != nil {
1072
- return fmt .Errorf ("error sending resource pack data info packet : %v " , err )
1072
+ return fmt .Errorf ("send ResourcePackDataInfo : %w " , err )
1073
1073
}
1074
1074
// Set the next expected packet to ResourcePackChunkRequest packets.
1075
1075
conn .expect (packet .IDResourcePackChunkRequest )
@@ -1085,12 +1085,12 @@ func (conn *Conn) handleResourcePackDataInfo(pk *packet.ResourcePackDataInfo) er
1085
1085
if ! ok {
1086
1086
// We either already downloaded the pack or we got sent an invalid UUID, that did not match any pack
1087
1087
// sent in the ResourcePacksInfo packet.
1088
- return fmt .Errorf ("unknown pack to download with UUID %v " , id )
1088
+ return fmt .Errorf ("unknown pack ( UUID=%v) " , id )
1089
1089
}
1090
1090
if pack .size != pk .Size {
1091
1091
// Size mismatch: The ResourcePacksInfo packet had a size for the pack that did not match with the
1092
1092
// size sent here.
1093
- conn .log .Printf ("pack %v had a different size in the ResourcePacksInfo packet than the ResourcePackDataInfo packet \n " , id )
1093
+ conn .log .Printf ("pack (UUID=%v) had a different size in ResourcePacksInfo than in ResourcePackDataInfo\n " , id )
1094
1094
pack .size = pk .Size
1095
1095
}
1096
1096
@@ -1126,13 +1126,13 @@ func (conn *Conn) handleResourcePackDataInfo(pk *packet.ResourcePackDataInfo) er
1126
1126
defer conn .packMu .Unlock ()
1127
1127
1128
1128
if pack .buf .Len () != int (pack .size ) {
1129
- conn .log .Printf ("incorrect resource pack size: expected %v, but got %v\n " , pack .size , pack .buf .Len ())
1129
+ conn .log .Printf ("incorrect resource pack size (UUID=%v) : expected %v, got %v\n " , id , pack .size , pack .buf .Len ())
1130
1130
return
1131
1131
}
1132
1132
// First parse the resource pack from the total byte buffer we obtained.
1133
1133
newPack , err := resource .Read (pack .buf )
1134
1134
if err != nil {
1135
- conn .log .Printf ("invalid full resource pack data for UUID %v : %v\n " , id , err )
1135
+ conn .log .Printf ("invalid full resource pack data ( UUID=%v) : %v\n " , id , err )
1136
1136
return
1137
1137
}
1138
1138
conn .packQueue .packAmount --
@@ -1154,16 +1154,16 @@ func (conn *Conn) handleResourcePackChunkData(pk *packet.ResourcePackChunkData)
1154
1154
if ! ok {
1155
1155
// We haven't received a ResourcePackDataInfo packet from the server, so we can't use this data to
1156
1156
// download a resource pack.
1157
- return fmt .Errorf ("resource pack chunk data for resource pack that was not being downloaded" )
1157
+ return fmt .Errorf ("chunk data for resource pack that was not being downloaded" )
1158
1158
}
1159
1159
lastData := pack .buf .Len ()+ int (pack .chunkSize ) >= int (pack .size )
1160
1160
if ! lastData && uint32 (len (pk .Data )) != pack .chunkSize {
1161
1161
// The chunk data didn't have the full size and wasn't the last data to be sent for the resource pack,
1162
1162
// meaning we got too little data.
1163
- return fmt .Errorf ("resource pack chunk data had a length of %v, but expected %v" , len (pk .Data ), pack . chunkSize )
1163
+ return fmt .Errorf ("expected chunk size %v, got %v" , pack . chunkSize , len (pk .Data ))
1164
1164
}
1165
1165
if pk .ChunkIndex != pack .expectedIndex {
1166
- return fmt .Errorf ("resource pack chunk data had chunk index %v, but expected %v" , pk . ChunkIndex , pack . expectedIndex )
1166
+ return fmt .Errorf ("expected chunk index %v, got %v" , pack . expectedIndex , pk . ChunkIndex )
1167
1167
}
1168
1168
pack .expectedIndex ++
1169
1169
pack .newFrag <- pk .Data
@@ -1175,10 +1175,10 @@ func (conn *Conn) handleResourcePackChunkData(pk *packet.ResourcePackChunkData)
1175
1175
func (conn * Conn ) handleResourcePackChunkRequest (pk * packet.ResourcePackChunkRequest ) error {
1176
1176
current := conn .packQueue .currentPack
1177
1177
if current .UUID () != pk .UUID {
1178
- return fmt .Errorf ("resource pack chunk request had unexpected UUID: expected %v, but got %v" , current .UUID (), pk .UUID )
1178
+ return fmt .Errorf ("expected pack UUID %v, but got %v" , current .UUID (), pk .UUID )
1179
1179
}
1180
1180
if conn .packQueue .currentOffset != uint64 (pk .ChunkIndex )* packChunkSize {
1181
- return fmt .Errorf ("resource pack chunk request had unexpected chunk index: expected %v, but got %v" , conn .packQueue .currentOffset / packChunkSize , pk .ChunkIndex )
1181
+ return fmt .Errorf ("expected pack UUID %v, but got %v" , conn .packQueue .currentOffset / packChunkSize , pk .ChunkIndex )
1182
1182
}
1183
1183
response := & packet.ResourcePackChunkData {
1184
1184
UUID : pk .UUID ,
@@ -1192,7 +1192,7 @@ func (conn *Conn) handleResourcePackChunkRequest(pk *packet.ResourcePackChunkReq
1192
1192
// If we hit an EOF, we don't need to return an error, as we've simply reached the end of the content
1193
1193
// AKA the last chunk.
1194
1194
if err != io .EOF {
1195
- return fmt .Errorf ("error reading resource pack chunk: %v " , err )
1195
+ return fmt .Errorf ("read resource pack chunk: %w " , err )
1196
1196
}
1197
1197
response .Data = response .Data [:n ]
1198
1198
@@ -1205,7 +1205,7 @@ func (conn *Conn) handleResourcePackChunkRequest(pk *packet.ResourcePackChunkReq
1205
1205
}()
1206
1206
}
1207
1207
if err := conn .WritePacket (response ); err != nil {
1208
- return fmt .Errorf ("error writing resource pack chunk data packet : %v " , err )
1208
+ return fmt .Errorf ("send ResourcePackChunkData : %w " , err )
1209
1209
}
1210
1210
1211
1211
return nil
@@ -1263,7 +1263,7 @@ func (conn *Conn) handleStartGame(pk *packet.StartGame) error {
1263
1263
// of the connection, and spawns the player.
1264
1264
func (conn * Conn ) handleRequestChunkRadius (pk * packet.RequestChunkRadius ) error {
1265
1265
if pk .ChunkRadius < 1 {
1266
- return fmt .Errorf ("requested chunk radius must be at least 1, got %v" , pk .ChunkRadius )
1266
+ return fmt .Errorf ("expected chunk radius of at least 1, got %v" , pk .ChunkRadius )
1267
1267
}
1268
1268
conn .expect (packet .IDSetLocalPlayerAsInitialised )
1269
1269
radius := pk .ChunkRadius
@@ -1295,7 +1295,7 @@ func (conn *Conn) handleRequestChunkRadius(pk *packet.RequestChunkRadius) error
1295
1295
// radius of the connection.
1296
1296
func (conn * Conn ) handleChunkRadiusUpdated (pk * packet.ChunkRadiusUpdated ) error {
1297
1297
if pk .ChunkRadius < 1 {
1298
- return fmt .Errorf ("new chunk radius must be at least 1, got %v" , pk .ChunkRadius )
1298
+ return fmt .Errorf ("expected chunk radius of at least 1, got %v" , pk .ChunkRadius )
1299
1299
}
1300
1300
conn .expect (packet .IDPlayStatus )
1301
1301
@@ -1311,7 +1311,7 @@ func (conn *Conn) handleChunkRadiusUpdated(pk *packet.ChunkRadiusUpdated) error
1311
1311
// logged in.
1312
1312
func (conn * Conn ) handleSetLocalPlayerAsInitialised (pk * packet.SetLocalPlayerAsInitialised ) error {
1313
1313
if pk .EntityRuntimeID != conn .gameData .EntityRuntimeID {
1314
- return fmt .Errorf ("entity runtime ID mismatch: entity runtime ID in StartGame and SetLocalPlayerAsInitialised packets should be equal" )
1314
+ return fmt .Errorf ("entity runtime ID mismatch: expected %v (from StartGame), got %v" , conn . gameData . EntityRuntimeID , pk . EntityRuntimeID )
1315
1315
}
1316
1316
if conn .waitingForSpawn .CompareAndSwap (true , false ) {
1317
1317
close (conn .spawn )
@@ -1325,7 +1325,7 @@ func (conn *Conn) handlePlayStatus(pk *packet.PlayStatus) error {
1325
1325
switch pk .Status {
1326
1326
case packet .PlayStatusLoginSuccess :
1327
1327
if err := conn .WritePacket (& packet.ClientCacheStatus {Enabled : conn .cacheEnabled }); err != nil {
1328
- return fmt .Errorf ("error sending client cache status : %v " , err )
1328
+ return fmt .Errorf ("send ClientCacheStatus : %w " , err )
1329
1329
}
1330
1330
// The next packet we expect is the ResourcePacksInfo packet.
1331
1331
conn .expect (packet .IDResourcePacksInfo )
@@ -1360,7 +1360,7 @@ func (conn *Conn) handlePlayStatus(pk *packet.PlayStatus) error {
1360
1360
_ = conn .Close ()
1361
1361
return fmt .Errorf ("cannot join an editor game on vanilla" )
1362
1362
default :
1363
- return fmt .Errorf ("unknown play status in PlayStatus packet %v" , pk .Status )
1363
+ return fmt .Errorf ("unknown play status %v" , pk .Status )
1364
1364
}
1365
1365
}
1366
1366
@@ -1391,7 +1391,7 @@ func (conn *Conn) enableEncryption(clientPublicKey *ecdsa.PublicKey) error {
1391
1391
return fmt .Errorf ("compact serialise server JWT: %w" , err )
1392
1392
}
1393
1393
if err := conn .WritePacket (& packet.ServerToClientHandshake {JWT : []byte (serverJWT )}); err != nil {
1394
- return fmt .Errorf ("error sending ServerToClientHandshake packet : %v " , err )
1394
+ return fmt .Errorf ("send ServerToClientHandshake: %w " , err )
1395
1395
}
1396
1396
// Flush immediately as we'll enable encryption after this.
1397
1397
_ = conn .Flush ()
0 commit comments