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

fix: Return error if subscription name already exists. #226

Merged
merged 3 commits into from
Aug 31, 2018

Conversation

stephenplusplus
Copy link
Contributor

Fixes #122

This could be a breaking change, depending on if you consider this a bug that we fixed or a behavior that we switched.

Before:

topic.createSubscription('my-subscription', function(err, subscription) {})

// in the future...
topic.createSubscription('my-subscription', function(err, subscription) {})

After:

topic.createSubscription('my-subscription', function(err, subscription) {})

// in the future...
topic.createSubscription('my-subscription', function(err, subscription) {
  // New error returned saying you already have a subscription with this name!
})

Here's a whole talk about some of the history: googleapis/google-cloud-node#1257

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 28, 2018
@ghost ghost assigned stephenplusplus Aug 28, 2018
Copy link
Contributor

@JustinBeckwith JustinBeckwith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're doing a semver major release at some point soon anyway :)

@codecov
Copy link

codecov bot commented Aug 28, 2018

Codecov Report

Merging #226 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #226   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines         807    807           
=====================================
  Hits          807    807
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4cf8b9b...f0f9a07. Read the comment docs.

@ghost ghost assigned JustinBeckwith Aug 30, 2018
@JustinBeckwith
Copy link
Contributor

@kinwa91 lets get this in 0.20 too.

@jkwlui jkwlui merged commit 8d6c1c1 into googleapis:master Aug 31, 2018
@art-pumpkin
Copy link

art-pumpkin commented Oct 1, 2018

@stephenplusplus @JustinBeckwith this was a breaking change for us, using the google bookshelf boilerplate...
What is the recommended workaround for getting the old behavior back? Could you please provide some insight? Thanks!

FYI for those experiencing the following error:
Error: 6 ALREADY_EXISTS: Resource already exists in the project (resource=YOUR_SUB_NAME)

I used the following snippet for promises-style. I needed to differentiate between a createSubscription object and a subscription object.

let subscriptionObject = await (async (topic, subscriptionName) => { try { return (await topic.createSubscription(subscriptionName))[0]; } catch (err) { if (err.code === 6) { logging.debug('Subscription Exists'); return await topic.subscription(subscriptionName); } else throw err; } })(topic, subscriptionName);

@stephenplusplus
Copy link
Contributor Author

You can do:

topic.createSubscription('my-subscription', function(err, subscription) {})

// in the future...
const subscription = topic.subscription('my-subscription')

subscription.get({ autoCreate: true }, function(err) {
  // No more `ALREADY_EXISTS` error!
})

Alternatively, if you know the subscription exists, you can just start using it right away:

const subscription = topic.subscription('my-subscription')

subscription.on('message', msg => {})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate subscription names silently fail
5 participants