Meteor Autorun() not running when accessing collection.property - meteor

Something strange is going on; when I run the following code, it works:
Deps.autorun(function() {
var room = Rooms.findOne({'room_id':Session.get('room_id')});
// var p = room.room_id;
console.log('autorun');
}
However, if I uncomment the var p line, it (the whole block) stops running. What's happening?

Found this in the depths of the Meteor.js documentation: "If the initial run of an autorun throws an exception, the computation is automatically stopped and won't be rerun."
On the first run of autorun, which is when the page is loaded, the database hasn't been loaded which throws an exception when you try to access room.room_id, and the autorun immediately stops from running again. Fixed by adding:
if (room) {
console.log(room.room_id);
...
}

Related

got has triggered a breakpoint error when load url

I use cefsharp(version:92.260) in my application. the application may crash when loading url, but not always.
below is my code:
Task.Factory.StartNew(() =>
{
var spinWait = new SpinWait();
while(!_Browser.IsBrowserInitialized)
{
spinWait.SpinOnce();
}
_Browser.Load(url);
});
I'd suggest you upgrade to a supported version, 103 at time of writing.
Improvements have been made, no longer is it nessicary to wait for IsBrowserInitialized to be equal to true before you can call Load(url).
You can just call Load without the IsBrowserInitialized check.

meteor-testing tutorial fails

I started the meteor-testing tutorial, but the 2nd automatic generated test fails with:
TypeError: Cannot call method 'url' of undefined
So it seems that the client variable is not defined. Did anybody experience similar issues? (btw is there a way to debug this)
i'm using ubuntu 14.04 with
Meteor 1.2.0.2
node v4.0.0
xolvio:cucumber 0.19.4_1 CucumberJS for Velocity
Update:
Generated test code intests/cucumber/features/step_definitions/sample_steps.js:
// You can include npm dependencies for support files in tests/cucumber/package.json
var _ = require('underscore');
module.exports = function () {
// You can use normal require here, cucumber is NOT run in a Meteor context (by design)
var url = require('url');
// 1st TEST OK
this.Given(/^I am a new user$/, function () {
server.call('reset'); // server is a connection to the mirror
});
// 2nd TEST FAIL
this.When(/^I navigate to "([^"]*)"$/, function (relativePath) {
// process.env.ROOT_URL always points to the mirror
client.url(url.resolve(process.env.ROOT_URL, relativePath));
});
...
};
I was said to file an issue in the chimp repository, where I was pointed to the solution:
// 2nd TEST FAIL
this.When(/^I navigate to "([^"]*)"$/, function (relativePath) {
// REPLACE client with browser
browser.url(url.resolve(process.env.ROOT_URL, relativePath));
});
This is a short fix, but I'm not sure whether you should later rather use client (seems to be wrapper for different environments).
**Update: ** meanwhile this was fixed, no adaption necessary anymore

Iron Router throwing exception in onData

I have seen a strange exception in the onData() function of a Route Controller in iron-router. The exception only seems to occur after I make a change to a file which of course causes meteor to restart the app. I've put up a sample in github that demonstrates the problem here: https://github.com/benmonro/iron-router-bug
If you add a person by clicking submit, then click on that person's name, everything will load fine. However, if you then make a change to some js (say add a comment). Meteor will reload and you'll get the exception in the 'onData()' method which is attempting to use a property of the data returned from the 'data()' function.
The exception is here:
> Exception in defer callback: TypeError: Cannot read property 'name' of
> undefined
> at RouteController.extend.onData (http://localhost:3000/irDataBug.js?8327f0bf1bedee2437ec14bc4509d8f7e85079ab:33:19)
> at RouteController.runHooks (http://localhost:3000/packages/iron-router.js?e9fac8016598ea034d4f30de5f0d356a9a24b6c5:827:16)
> at http://localhost:3000/packages/iron-router.js?e9fac8016598ea034d4f30de5f0d356a9a24b6c5:2137:16
> at Utils.extend._run.withNoStopsAllowed (http://localhost:3000/packages/iron-router.js?e9fac8016598ea034d4f30de5f0d356a9a24b6c5:2098:21)
> at _assign._compute (http://localhost:3000/packages/deps.js?4a82362ae66e863a1c1a8b0a5fec6f665e2038d1:228:38)
> at new Deps.Computation (http://localhost:3000/packages/deps.js?4a82362ae66e863a1c1a8b0a5fec6f665e2038d1:160:10)
> at Object._assign.autorun (http://localhost:3000/packages/deps.js?4a82362ae66e863a1c1a8b0a5fec6f665e2038d1:380:13)
> at http://localhost:3000/packages/iron-router.js?e9fac8016598ea034d4f30de5f0d356a9a24b6c5:2134:12
> at Utils.extend._run.withNoStopsAllowed (http://localhost:3000/packages/iron-router.js?e9fac8016598ea034d4f30de5f0d356a9a24b6c5:2098:21)
> at _assign._compute (http://localhost:3000/packages/deps.js?4a82362ae66e863a1c1a8b0a5fec6f665e2038d1:228:38)
The data isn't ready after the reload so you need to add a guard or an early return to the callback. Here's a simple fix:
onData: function() {
var thePerson = Router.current().data();
if (!thePerson)
return;
if (thePerson.name === "Fred") {
console.log("it's fred");
} else {
console.log("it's not fred");
}
}
Because the callback is reactive, it will rerun once thePerson is found. Alternative solutions could involve a waitOn callback and then checking for this.ready().

Meteor: The application is not spiderable

My application is not spiderable both on local and production.
When I go to http://localhost:3000/?_escaped_fragment_=, I can see the following error appears (phantom is killed after 15 seconds):
spiderable: phantomjs failed: { [Error: Command failed: ] killed: true, code: null, signal: 'SIGTERM' }
It seems that many other people got this problem:
https://github.com/gadicc/meteor-phantomjs/issues/1
https://groups.google.com/forum/#!msg/meteor-talk/Lnm9HFs4MgM/YKDMR80fVecJ
https://groups.google.com/forum/#!topic/meteor-talk/7ZbidddRGo4
The thing is I am not using observatory or select2 and all my publications return a cursor. According to me, the problem comes from the minification. I just read in this thread that someone succeed to display "SyntaxError: Parse error". How can I know more about what is going wrong with Phantom and which file is causing the problem?
This happens when spiderable is waiting for subscriptions that fail to return any data and end up timing out, as mentioned in some of the threads you linked.
Make sure that all of your publish functions are either returning a cursor, a (possibly empty) list of cursors, or sending this.ready().
Meteor APM may be useful in determining which publications aren't returning.
If you want to know more about what is wrong with phatomjs, you might try this code (1):
// Put your URL below, no "?_escaped_fragment_=" necessary
var url = "http://your-url.com/";
var page = require('webpage').create();
page.open(url);
setInterval(function() {
var ready = page.evaluate(function () {
if (typeof Meteor !== 'undefined'
&& typeof(Meteor.status) !== 'undefined'
&& Meteor.status().connected) {
Deps.flush();
return DDP._allSubscriptionsReady();
}
return false;
});
if (ready) {
var out = page.content;
out = out.replace(/<script[^>]+>(.|\n|\r)*?<\/script\s*>/ig, '');
out = out.replace('<meta name=\"fragment\" content=\"!\">', '');
console.log(out);
phantom.exit();
}
}, 100);
For use in local, install phantomjs. Then outside your app, create a file phantomtest.js with the code above. And run phantomjs phantomtest.js
Another thing that maybe you can try is to use UglifyJS to catch some errors in the minified JS file as Payner35 did.
My problem was coming from SSL. You can have a complete overview of what I did here.
Edit the spiderable source and add --ignore-ssl-errors=yes to the phantomjs command line, it will work.

Meteor error message: "Failed to receive keepalive! Exiting."

I am just starting to build a new Meteor app. The only thing I have done so far is add one Collection. It will start, run fine for about 5 minutes, and then give me the error message "Failed to receive keepalive! Exiting."
What is failing to receive keepalive from what? I assume this has something to do with Mongo since that is the only thing I have added. Googling the error message turns up nothing except Meteor sites that are just showing this error message instead of the their app.
My MongoDB collection already had data in it that was not created by Meteor and it is over 4GB if that makes any difference.
This is the complete app.
pitches_sum = new Meteor.Collection( 'pitches_sum' );
if (Meteor.is_client) {
Template.hello.greeting = function () {
return "Welcome to my site.";
};
Template.hello.events = {
'click input' : function () {
// template data, if any, is available in 'this'
if (typeof console !== 'undefined')
console.log("You pressed the button");
}
};
}
if (Meteor.is_server) {
Meteor.startup(function () {
console.log( '**asdf**' );
});
}
If I comment out the pitches_sum = new Meteor.Collection( 'pitches_sum' ); line, then I don't think I will get the error message any more.
This was being caused by my large data set and autopublish. Since autopublish was on, Meteor was trying to send the whole 4GB collection down to the client. Trying to process all the data prevented the client from responding to the server's keep alive pings. Or something to that effect.
Removing autopublish with meteor remove autopublish and then writing my own publish and subscribe functions fixed the problem.

Resources