@@ -100,7 +100,7 @@ func (s *Server) ListResource(ctx context.Context, fwReq *ListRequest, fwStream
100100 }
101101 }
102102
103- resp := ListResult {}
103+ diagsStream := & list. ListResultsStream {}
104104
105105 if listResourceWithConfigure , ok := listResource .(list.ListResourceWithConfigure ); ok {
106106 logging .FrameworkTrace (ctx , "ListResource implements ListResourceWithConfigure" )
@@ -115,12 +115,29 @@ func (s *Server) ListResource(ctx context.Context, fwReq *ListRequest, fwStream
115115 listResourceWithConfigure .Configure (ctx , configureReq , & configureResp )
116116 logging .FrameworkTrace (ctx , "Called provider defined ListResource Configure" )
117117
118- resp .Diagnostics .Append (configureResp .Diagnostics ... )
118+ if len (configureResp .Diagnostics ) > 0 {
119+ diagsResp := list.ListResult {}
119120
120- if resp .Diagnostics .HasError () {
121- return
122- }
121+ diagsResp .Diagnostics .Append (configureResp .Diagnostics ... )
122+
123+ // Captures any diags from the Configure call
124+ diagsStream .Results = func (push func (list.ListResult ) bool ) {
125+ if ! push (diagsResp ) {
126+ return
127+ }
128+ }
123129
130+ if diagsResp .Diagnostics .HasError () {
131+ fwStream .Results = func (push func (ListResult ) bool ) {
132+ for result := range diagsStream .Results {
133+ if ! push (ListResult (result )) {
134+ return
135+ }
136+ }
137+ }
138+ return
139+ }
140+ }
124141 }
125142
126143 req := list.ListRequest {
@@ -142,17 +159,20 @@ func (s *Server) ListResource(ctx context.Context, fwReq *ListRequest, fwStream
142159 stream .Results = list .NoListResults
143160 }
144161
145- // How should we handle the diags produced by Configure called on line 115? Appending them to an empty stream
146- // might be misleading, not to mention will error below because Identity will be nil
162+ if diagsStream .Results == nil {
163+ diagsStream .Results = list .NoListResults
164+ }
147165
148- fwStream .Results = processListResults (req , stream .Results )
166+ fwStream .Results = processListResults (req , stream .Results , diagsStream . Results )
149167}
150168
151- func processListResults (req list.ListRequest , stream iter.Seq [list.ListResult ]) iter.Seq [ListResult ] {
169+ func processListResults (req list.ListRequest , streams ... iter.Seq [list.ListResult ]) iter.Seq [ListResult ] {
152170 return func (push func (ListResult ) bool ) {
153- for result := range stream {
154- if ! push (processListResult (req , result )) {
155- return
171+ for _ , stream := range streams {
172+ for result := range stream {
173+ if ! push (processListResult (req , result )) {
174+ return
175+ }
156176 }
157177 }
158178 }
@@ -165,6 +185,11 @@ func processListResult(req list.ListRequest, result list.ListResult) ListResult
165185 return ListResult (result )
166186 }
167187
188+ // Allow any non-error diags to pass through
189+ if len (result .Diagnostics ) > 0 && result .DisplayName == "" && result .Identity == nil && result .Resource == nil {
190+ return ListResult (result )
191+ }
192+
168193 if result .Identity == nil || result .Identity .Raw .IsNull () {
169194 return ListResultError (
170195 "Incomplete List Result" ,
0 commit comments