Skip to content

Commit 3e5c9f7

Browse files
committed
Add utility functions for list results stream errors
1 parent ce2bb12 commit 3e5c9f7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

list/list_resource.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ type ListResultsStream struct {
134134
// NoListResults is an iterator that pushes zero results.
135135
var NoListResults = func(func(ListResult) bool) {}
136136

137+
// ListResultsStreamError returns a function that yields a single
138+
// [[ListResult]] with an error diagnostic
139+
func ListResultsStreamError(summary string, detail string) iter.Seq[ListResult] {
140+
return func(push func(ListResult) bool) {
141+
if !push(ListResultError(summary, detail)) {
142+
return
143+
}
144+
}
145+
}
146+
147+
// ListResultError constructs a [[ListResult]] with an error diagnostic
148+
func ListResultError(summary string, detail string) ListResult {
149+
return ListResult{
150+
Diagnostics: diag.Diagnostics{
151+
diag.NewErrorDiagnostic(summary, detail),
152+
},
153+
}
154+
}
155+
137156
// ListResult represents a listed managed resource instance.
138157
type ListResult struct {
139158
// Identity is the identity of the managed resource instance.

0 commit comments

Comments
 (0)