File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,16 @@ type ReadStateBytesStream struct {
5757}
5858
5959type WriteStateBytesStream struct {
60- Chunks iter.Seq2 [WriteStateByteChunk , error ]
60+ Messages iter.Seq [WriteStateBytesStreamMsg ]
61+ }
62+
63+ // WriteStateBytesStreamMsg contains paired data:
64+ // 1. A chunk of state data, received from Terraform core to be persisted.
65+ // 2. Any gRPC-related errors the provider server encountered when
66+ // receiving data from Terraform core.
67+ type WriteStateBytesStreamMsg struct {
68+ Chunk WriteStateByteChunk
69+ Err error
6170}
6271
6372type WriteStateBytesResponse struct {
Original file line number Diff line number Diff line change @@ -1644,8 +1644,7 @@ func (s *server) WriteStateBytes(srv grpc.ClientStreamingServer[tfplugin6.WriteS
16441644 return err
16451645 }
16461646
1647- // Trying an aproach using iter.Seq2
1648- iterator := func (yield func (tfprotov6.WriteStateByteChunk , error ) bool ) {
1647+ iterator := func (yield func (tfprotov6.WriteStateBytesStreamMsg ) bool ) {
16491648 for {
16501649 chunk , err := srv .Recv ()
16511650 if err == io .EOF {
@@ -1658,22 +1657,26 @@ func (s *server) WriteStateBytes(srv grpc.ClientStreamingServer[tfplugin6.WriteS
16581657 ))
16591658 }
16601659
1661- ok := yield (tfprotov6.WriteStateByteChunk {
1662- Bytes : chunk .Bytes ,
1663- TotalLength : chunk .TotalLength ,
1664- Range : tfprotov6.StateByteRange {
1665- Start : chunk .Range .Start ,
1666- End : chunk .Range .End ,
1667- },
1668- }, err )
1660+ ok := yield (
1661+ tfprotov6.WriteStateBytesStreamMsg {
1662+ Chunk : tfprotov6.WriteStateByteChunk {
1663+ Bytes : chunk .Bytes ,
1664+ TotalLength : chunk .TotalLength ,
1665+ Range : tfprotov6.StateByteRange {
1666+ Start : chunk .Range .Start ,
1667+ End : chunk .Range .End ,
1668+ },
1669+ },
1670+ Err : err , // If this isn't nil, it'll be a gRPC error from Recv
1671+ })
16691672 if ! ok {
16701673 return
16711674 }
16721675 }
16731676 }
16741677
16751678 resp , err := server .WriteStateBytes (ctx , & tfprotov6.WriteStateBytesStream {
1676- Chunks : iterator ,
1679+ Messages : iterator ,
16771680 })
16781681 if err != nil {
16791682 return err
You can’t perform that action at this time.
0 commit comments