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

Errors in publications aren't handled properly #22

Open
mizzao opened this issue Jan 8, 2018 · 1 comment
Open

Errors in publications aren't handled properly #22

mizzao opened this issue Jan 8, 2018 · 1 comment

Comments

@mizzao
Copy link

mizzao commented Jan 8, 2018

Using the $subscribe function with Vue dynamic arguments doesn't work properly if the publication throws an error.

  • The previous subscription (which didn't have an error) is not stopped, so the data persists client-side.
  • There is no way to display or otherwise react to the error on the client.

In my app, this results in a situation where the subscription update fails silently (and $subReady never updates), and then a new subscription without error results in both the data from the old and new subscription being displayed.

Not all subscriptions can be validated and guaranteed not to have an error client-side, so this creates a bit of a mess with regard to possible user error.

@red-meadow
Copy link

The issue is caused by this block of code:

const autorun = this.$autorun(() => {
  // Failed subscription will never be ready
  const ready = handle.ready()
  set(this.$data.$meteor.subs, key, ready)
  // So the following code will never be executed
  if (ready && oldSub) {
    this.$stopHandle(oldSub)
  }
})

There is no way to display or otherwise react to the error on the client.

Actually it's partially possible:

$subscribe: {
  'sub.name': [arg1, arg2, {
    onStop(err) { if (err) /* do something */ }
  }]
}

It must be possible to use onStop callback in the package code as well to determine whether a subscription is not ready due to error. Then with a condition

if ((ready || error) && oldSub) {
  this.$stopHandle(oldSub)
}

the issue must be solved.

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

No branches or pull requests

3 participants