@@ -1644,30 +1644,19 @@ func (s *server) WriteStateBytes(srv grpc.ClientStreamingServer[tfplugin6.WriteS
16441644 return err
16451645 }
16461646
1647- iterator := func (yield func (tfprotov6.WriteStateByteChunk ) bool ) {
1647+ // Trying an aproach using iter.Seq2
1648+ iterator := func (yield func (tfprotov6.WriteStateByteChunk , error ) bool ) {
16481649 for {
16491650 chunk , err := srv .Recv ()
16501651 if err == io .EOF {
16511652 break
16521653 }
16531654 if err != nil {
1654- // attempt to send the error back to client
1655- msgErr := srv .SendMsg (& tfplugin6.WriteStateBytes_Response {
1656- Diagnostics : toproto .Diagnostics ([]* tfprotov6.Diagnostic {
1657- {
1658- Severity : tfprotov6 .DiagnosticSeverityError ,
1659- Summary : "Writing state chunk failed" ,
1660- Detail : fmt .Sprintf ("Attempt to write a byte chunk of state %q to %q failed: %s" ,
1661- chunk .StateId , chunk .TypeName , err ),
1662- },
1663- }),
1664- })
1665- if msgErr != nil {
1666- err := status .Error (codes .Unimplemented , "ProviderServer does not implement WriteStateBytes" )
1667- logging .ProtocolError (ctx , err .Error ())
1668- return
1669- }
1670- return
1655+ logging .ProtocolError (ctx , fmt .Sprintf (
1656+ "WriteStateBytes experienced an error when receiving state data from Terraform: %s" ,
1657+ err ,
1658+ ),
1659+ )
16711660 }
16721661
16731662 ok := yield (tfprotov6.WriteStateByteChunk {
@@ -1677,11 +1666,10 @@ func (s *server) WriteStateBytes(srv grpc.ClientStreamingServer[tfplugin6.WriteS
16771666 Start : chunk .Range .Start ,
16781667 End : chunk .Range .End ,
16791668 },
1680- })
1669+ }, err )
16811670 if ! ok {
16821671 return
16831672 }
1684-
16851673 }
16861674 }
16871675
0 commit comments