Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

Stub exceptions are logged instead of thrown in Meteor Methods, preventing throwStubExceptions from working as intended #438

Open ThaumRystra opened 2 years ago

ThaumRystra commented 2 years ago

Because of this block, all exceptions that would throw on the server when calling Collection.update without a callback instead log on the client instead, which is inconsistent and breaks simulated methods.

The comment for the same block claims "Client can't block, so it can't report errors by exception" is misleading. In simulated methods the client can report errors by exception just fine.

The default for meteor:validatedMethods is for throwStubExceptions to be true, which should prevent methods that error on the client from being sent to the server, but because of the enforced callback on update and insert collection methods, the client cannot simulate the server's behavior correctly.

To Reproduce

  1. Call Collection.update( ) in a validated method using an update that does not match the schema
  2. The update succeeds on the client, but logs an error, and then throws the same error on the server which gets returned to the client's method callback

Expected behavior

Collection.update should throw an error consistently on both the client and the server when used without a callback.