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

Expose error constant for consumer name already in use #977

Closed
2 tasks done
mprimi opened this issue May 16, 2022 · 2 comments · Fixed by #1044
Closed
2 tasks done

Expose error constant for consumer name already in use #977

mprimi opened this issue May 16, 2022 · 2 comments · Fixed by #1044
Assignees
Labels
bug Confirmed reproducible bug

Comments

@mprimi
Copy link

mprimi commented May 16, 2022

Defect

Make sure that these boxes are checked before submitting your issue -- thank you!

Versions of nats.go and the nats-server if one was involved:

nats.go v1.14.0

OS/Container environment:

N/A

Steps or code to reproduce the issue:

Try to add a consumer when a consumer with the same name exists

js.AddConsumer("some stream", consumerConfig)
js.AddConsumer("some stream", consumerConfig)

The error is expected, as the consumer exists!
However, one has to do manual string comparison because an error constant is not provided for this case.

Here's an example from this repo itself:

				(strings.Contains(cinfo.Error.Description, `consumer already exists`) ||
					strings.Contains(cinfo.Error.Description, `consumer name already in use`)) {

Expected result:

This is what I wish I could do:

  consumerInfo, err := js.AddConsumer(streamName, consumerConfig)
  if err == nats.ErrConsumerExists {
    // consumer exists - do what is appropriate
  }

Actual result:

This is what I'm forced to do (brittle and ugly):

  consumerInfo, err := js.AddConsumer(streamName, consumerConfig)
  if err != nil && fmt.Sprintf("%s", err) == "consumer name already in use" {
    // consumer exists - do what is appropriate
  }
@mprimi mprimi added the bug Confirmed reproducible bug label May 16, 2022
@wallyqs
Copy link
Member

wallyqs commented May 16, 2022

Sounds good to me to add, we could have ErrConsumerNameAlreadyInUse similar to ErrStreamNameAlreadyInUse that already exists.

@ripienaar
Copy link
Contributor

This client really should support the jetstream error codes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed reproducible bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants