encore icon indicating copy to clipboard operation
encore copied to clipboard

PubSub Subscription doesn't work if provided as variable vs a string literal

Open preslavmihaylov opened this issue 9 months ago • 3 comments

I have a subscription whose identifier I've set as a constant, defined elsewhere.

The encore compiler doesn't allow me to do that because it checks whether the variable identifier matches the spec for the value its supposed to contain.

Example: image

However, the value within that variable does conform to the spec expected by encore:

const pubSubSubscriptionName = "forum-post-tagger"

preslavmihaylov avatar Apr 28 '24 11:04 preslavmihaylov

I see in the error message that it expects a string literal, but it would be nice if that can be passed as a variable as I like to keep constants like that defined in the same package to easily spot that eg two services have the same subscription name.

preslavmihaylov avatar Apr 28 '24 11:04 preslavmihaylov

What's the use case for having "two services have the same subscription name"? A subscription can only be tied to a single service.

eandre avatar May 23 '24 09:05 eandre

That's what I'm trying to avoid, which is why I prefer the constants route (stored in the same file) because that way, if I accidentally define a subscription twice for different services, it would be easier to spot the error.

Having said that, if Encore automatically detects duplicate subscriptions & errors out if so, then that is a viable solution as well.

preslavmihaylov avatar May 23 '24 09:05 preslavmihaylov