Repository: googleapis/gapic-generator-go
Pull request #1561 (2024-08-23 15:47:21)

fix: make iter error handling clearer


Patch:
diff --git a/internal/gengapic/example.go b/internal/gengapic/example.go
index 213bb61..2061dd0 100644
--- a/internal/gengapic/example.go
+++ b/internal/gengapic/example.go
@@ -333,7 +333,7 @@ func (g *generator) examplePagingAllCall(m *descriptorpb.MethodDescriptorProto)
 
 	p("for resp, err := range c.%s(ctx, req).All() {", m.GetName())
 	p("  if err != nil {")
-	p("    // TODO: Handle error.")
+	p("    // TODO: Handle error and break/return/continue. Iteration will stop after any error.")
 	p("  }")
 	p("  // TODO: Use resp.")
 	p("  _ = resp")


Test patch:
diff --git a/internal/gengapic/testdata/custom_op_example_all.want b/internal/gengapic/testdata/custom_op_example_all.want
index 9b181e7..f4ea638 100644
--- a/internal/gengapic/testdata/custom_op_example_all.want
+++ b/internal/gengapic/testdata/custom_op_example_all.want
@@ -17,7 +17,7 @@ func ExampleFooClient_GetManyThings_all() {
 	}
 	for resp, err := range c.GetManyThings(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
diff --git a/internal/gengapic/testdata/empty_example_all.want b/internal/gengapic/testdata/empty_example_all.want
index 7a234b4..b2bc4e0 100644
--- a/internal/gengapic/testdata/empty_example_all.want
+++ b/internal/gengapic/testdata/empty_example_all.want
@@ -17,7 +17,7 @@ func ExampleClient_GetManyThings_all() {
 	}
 	for resp, err := range c.GetManyThings(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
@@ -43,7 +43,7 @@ func ExampleClient_ListLocations_all() {
 	}
 	for resp, err := range c.ListLocations(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
@@ -69,7 +69,7 @@ func ExampleClient_ListOperations_all() {
 	}
 	for resp, err := range c.ListOperations(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
diff --git a/internal/gengapic/testdata/empty_example_grpc_all.want b/internal/gengapic/testdata/empty_example_grpc_all.want
index 7a234b4..b2bc4e0 100644
--- a/internal/gengapic/testdata/empty_example_grpc_all.want
+++ b/internal/gengapic/testdata/empty_example_grpc_all.want
@@ -17,7 +17,7 @@ func ExampleClient_GetManyThings_all() {
 	}
 	for resp, err := range c.GetManyThings(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
@@ -43,7 +43,7 @@ func ExampleClient_ListLocations_all() {
 	}
 	for resp, err := range c.ListLocations(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
@@ -69,7 +69,7 @@ func ExampleClient_ListOperations_all() {
 	}
 	for resp, err := range c.ListOperations(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
diff --git a/internal/gengapic/testdata/foo_example_all.want b/internal/gengapic/testdata/foo_example_all.want
index 3da4d43..d9a501d 100644
--- a/internal/gengapic/testdata/foo_example_all.want
+++ b/internal/gengapic/testdata/foo_example_all.want
@@ -17,7 +17,7 @@ func ExampleFooClient_GetManyThings_all() {
 	}
 	for resp, err := range c.GetManyThings(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
@@ -43,7 +43,7 @@ func ExampleFooClient_ListLocations_all() {
 	}
 	for resp, err := range c.ListLocations(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
@@ -69,7 +69,7 @@ func ExampleFooClient_ListOperations_all() {
 	}
 	for resp, err := range c.ListOperations(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
diff --git a/internal/gengapic/testdata/foo_example_rest_all.want b/internal/gengapic/testdata/foo_example_rest_all.want
index 146e649..1e5e7d9 100644
--- a/internal/gengapic/testdata/foo_example_rest_all.want
+++ b/internal/gengapic/testdata/foo_example_rest_all.want
@@ -17,7 +17,7 @@ func ExampleFooClient_GetManyThings_all() {
 	}
 	for resp, err := range c.GetManyThings(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
@@ -43,7 +43,7 @@ func ExampleFooClient_ListLocations_all() {
 	}
 	for resp, err := range c.ListLocations(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp
@@ -69,7 +69,7 @@ func ExampleFooClient_ListOperations_all() {
 	}
 	for resp, err := range c.ListOperations(ctx, req).All() {
 		if err != nil {
-			// TODO: Handle error.
+			// TODO: Handle error and break/return/continue. Iteration will stop after any error.
 		}
 		// TODO: Use resp.
 		_ = resp