Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pubsub: docs example for Subscription.Receive is incorect #9045

Closed
dtam-cybozu opened this issue Nov 27, 2023 · 1 comment · Fixed by #9516
Closed

pubsub: docs example for Subscription.Receive is incorect #9045

dtam-cybozu opened this issue Nov 27, 2023 · 1 comment · Fixed by #9516
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. type: docs Improvement to the documentation for an API.

Comments

@dtam-cybozu
Copy link

dtam-cybozu commented Nov 27, 2023

Client

PubSub

Environment

N/A

Go Environment

N/A

Code

According to this example https://github.com/googleapis/google-cloud-go/blob/main/pubsub/example_test.go#L313-L329 we are supposed to assume that something has gone wrong if err != context.Canceled but I had a very quick skim through the Receive source and it seems like it often returns nil (notably, including when ctx is done).

	err = sub.Receive(ctx, func(ctx context.Context, m *pubsub.Message) {
		// TODO: Handle message.
		m.Ack()
	})
	if err != context.Canceled {
		// TODO: Handle error.
	}

Expected behavior

I'm not exactly sure if Receive() ever returns context.Canceled so I can't say whether the condition should look like:

if err != nil {
	// TODO: Handle error.
}

but it should at least look like this if I'm not mistaken:

if err != nil && err != context.Canceled {
	// TODO: Handle error.
}

Please let me know if I've made a mistake, thanks :)

@dtam-cybozu dtam-cybozu added the triage me I really want to be triaged. label Nov 27, 2023
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Nov 27, 2023
@dtam-cybozu dtam-cybozu changed the title pubsub: example for Subscription.Receive is incorect pubsub: docs example for Subscription.Receive is incorect Nov 27, 2023
@hongalex hongalex added type: docs Improvement to the documentation for an API. and removed triage me I really want to be triaged. labels Nov 29, 2023
@hongalex
Copy link
Member

Good catch. You're correct in that a nil error does not need to be handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. type: docs Improvement to the documentation for an API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants