Nyxynyx
Nyxynyx

Reputation: 63599

Prevent Meteor.js from Restarting on Error

When Meteor.js is started using the mrt command, it automatically restarts the app 3 times when an error occurs.

Is it possible to avoid restarting on error (just let the error crash and exit the process), or change the number of times Meteor will attempt the restart.

Upvotes: 1

Views: 546

Answers (1)

Tarang
Tarang

Reputation: 75945

You need to catch the errors and handle them if you want it to work this way.

You can't prevent a syntax error from stopping meteor restarting though, because it can't start in the first place!

Meteor automatically stops apps from crashing provided the errors occur in Meteor.startup(), Meteor.methods, or Meteor.publish

If you have 'free hanging code' that isn't in any of those you need to handle it with try and catch i.e

try {

    //Somewhere the errors always come from

}
catch(e) {
    //Report the error?
    console.log(e.message);
}

If you don't want to catch it you'll need to run the code in any of the Meteor closures (Meteor.methods, Meteor.publish, Meteor.startup, Meteor.setTimeout, Meteor.setInterval).

If you have any external modules or something that runs that is in a method that is asynchronous you need to make sure that it runs within the same Fiber, with Meteor.bindEnvironment or Meteor._wrapAsync (usually for npm modules) so that the error occurs where it originated from and not on its own.

Upvotes: 1

Related Questions