@@ -45,8 +45,9 @@ func (r *ThingListResource) List(ctx context.Context, req list.ListRequest, stre
4545 var data ThingListResourceModel
4646
4747 // Read list config data into the model
48- resp.Diagnostics .Append (req.Config .Get (ctx, &data)...)
49- if resp.Diagnostics .HasError () {
48+ diags := req.Config .Get (ctx, &data)...
49+ if diags.HasError () {
50+ stream.Results = list.ListResultsStreamDiagnostics (diags)
5051 return
5152 }
5253
@@ -57,30 +58,23 @@ func (r *ThingListResource) List(ctx context.Context, req list.ListRequest, stre
5758 // Define the function that will push results into the stream
5859 stream.Results = func (push func (list.ListResult ) bool ) {
5960 for _ , thing := range things {
60- // Initialize a new result object for each thing
61- result := req.NewListResult (ctx)
62-
63- // Set the user-friendly name of this thing
64- result.DisplayName = thing.Name
65-
66- // Set resource identity data on the result
67- resp.Diagnostics .Append (result.Identity .Set (ctx, thing.ID ))
68- if resp.Diagnostics .HasError () {
69- return
70- }
71-
72- // Set the resource information on the result
73- resp.Diagnostics .Append (result.Resource .Set (ctx, thing.Resource ))
74- if resp.Diagnostics .HasError () {
75- return
76- }
77-
78- // Send the result to the stream.
79- if !push (result) {
80- return
81- }
82- }
83- }
61+ // Initialize a new result object for each thing
62+ result := req.NewListResult (ctx)
63+
64+ // Set the user-friendly name of this thing
65+ result.DisplayName = thing.Name
66+
67+ // Set resource identity data on the result
68+ result.Diagnostics .Append (result.Identity .Set (ctx, thing.ID ))
69+
70+ // Set the resource information on the result
71+ result.Diagnostics .Append (result.Resource .Set (ctx, thing.Resource ))
72+
73+ // Send the result to the stream.
74+ if !push (result) {
75+ return
76+ }
77+ }
8478}
8579` ` `
8680
0 commit comments