Saturday 8 April 2017

Exception from Tracker recompute function and sub user id, Match error

I have a user publish and subscribe problem. When I click on a user name, it is supposed to show: [1] user's profile image; and [2] all posts from that user.

However it just shows a loading spinner screen and the below errors. If I try a couple of refresh or re-clicking the name, the page eventually loads with some lag.

I suspect a client race condition but I tried adding a (!this._id) return [ ] or this.ready();, the posts would flash on screen once and not show up thereafter. I cant remove the check as it throws a no check error.

If theres anywhere to simplify showing posts of the user, please kindly advise. Thanks!

error on the browser console:

Exception from Tracker recompute function: meteor.js:930:11

undefined meteor.js:932:11

selected portions of the key error shown on terminal:

> I20170409-11:51:58.787(8)? Exception from sub user id
> BRFKAiwEXKootpbwY Error: Match error: Expected string, got null
> (packages/check/match.js:34:1) I20170409-11:51:58.788(8)?     at
> Subscription.<anonymous> (server/server.js:86:2)
> I20170409-11:51:58.788(8)?     at Subscription.prepareOptions
> (packages/reywood_publish-composite/packages/reywood_publish-composite.js:440:1)
> I20170409-11:51:58.788(8)?     at Subscription._handler
> (packages/reywood_publish-composite/packages/reywood_publish-composite.js:408:1)
> I20170409-11:51:58.788(8)?     at packages/check/match.js:107:1 
> at Object.exports.Match._failIfArgumentsAreNotAllChecked
> (packages/check/match.js:106:1) I20170409-11:51:58.788(8)?     at
> maybeAuditArgumentChecks
> Match failed [400]

The server publish

Meteor.publish('userDetails', function() {
    var fields = { 
        username    : 1, 
        emails      : 1, 
        profile     : 1,
        md5hash     : 1 
    };
    return Meteor.users.find( {}, { fields: fields });
});

Meteor.publishComposite('user', function (_id) {
    check(_id, String);  // cant remove this check, throws error
    //if (!this._id)  return this.ready(); or [] doesnt work 
        return {
            find: function() {
                return Meteor.users.find({ _id: _id }, { 
                    fields: { 
                        username    : 1, 
                        emails      : 1, 
                        profile     : 1,
                        md5hash     : 1 
                    }
                });
            },
                children: [
                    { 
                        find: function(user) { 
                            return Posts.find({ userId: user._id }); 
                        } 
                    } 
                ]
        };
});

Router code

Router.route('/users/:_id',      { 
  name: 'users.show',     
   onBeforeAction: function () {
      if( this.params._id === Meteor.userId() ){ 
         Router.go('profile');
      } else {
         this.next();
      }
   }
});

the page js

Template.usersShow.onCreated(function(){
   var self = this;
   self.autorun(function(){
      self.subscribe('user', Router.current().params._id);
   });
});
Template.usersShow.helpers({
   user: function () {
      return Meteor.users.findOne({ _id: Router.current().params._id });
   },
   posts: function () {
      return Posts.find({ userId: Router.current().params._id });
   }
});



via Thinkerer

No comments:

Post a Comment