mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Don't use _.once or instanceof with uniload
_.once has the problem that if you call the once'd function while it is still in progress (re-entrantly or in another Fiber), it returns undefined immediately. That's bad for uniload! uniload already has a cache, so just use that. (In the future, perhaps detect an attempt to uniload something that's currently in the process of being uniloaded in another fiber and block until the other fiber is ready.) Using instanceof with things you've uniloaded is a little sketchy: maybe two different uniload calls will end up with two different copies of Package.meteor.Meteor.Error, and it seems kind of hairy to ensure you're not mixing and matching copies. However, Meteor.Errors are all tagged with a string errorType, which fills me with much less fear, uncertainty, and doubt than instanceof.
This commit is contained in:
@@ -15,12 +15,11 @@ var uniload = require('./uniload.js');
|
||||
|
||||
var auth = exports;
|
||||
|
||||
var getLoadedPackages = _.once(function () {
|
||||
var uniload = require('./uniload.js');
|
||||
var getLoadedPackages = function () {
|
||||
return uniload.load({
|
||||
packages: [ 'meteor', 'livedata' ]
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Opens and returns a DDP connection to the accounts server. Remember
|
||||
// to close it when you're done with it!
|
||||
@@ -946,7 +945,7 @@ exports.registerOrLogIn = withAccountsConnection(function (connection) {
|
||||
);
|
||||
} catch (e) {
|
||||
stopSpinner();
|
||||
if (! (e instanceof getLoadedPackages().meteor.Meteor.Error))
|
||||
if (e.errorType !== "Meteor.Error")
|
||||
throw e;
|
||||
process.stderr.write(
|
||||
"When you've picked your password, run 'meteor login' to log in.\n")
|
||||
@@ -1083,7 +1082,7 @@ exports.loginWithTokenOrOAuth = function (conn, url, domain, sessionType) {
|
||||
// If we get a Meteor.Error, then we swallow it and go on to
|
||||
// attempt an OAuth flow and get a new token. If it's not a
|
||||
// Meteor.Error, then we leave it to the caller to handle.
|
||||
if (! err instanceof Package.meteor.Meteor.Error) {
|
||||
if (err.errorType !== "Meteor.Error") {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ var ServiceConnection = require('./service-connection.js');
|
||||
var stats = require('./stats.js');
|
||||
|
||||
// a bit of a hack
|
||||
var getPackage = _.once(function () {
|
||||
var getPackage = function () {
|
||||
return uniload.load({
|
||||
packages: [ 'meteor', 'livedata' ]
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// If 'error' is an exception that we know how to report in a
|
||||
// user-friendly way, print an approprite message to stderr and return
|
||||
@@ -260,8 +260,7 @@ exports.deploy = function (options) {
|
||||
try {
|
||||
conn.call('createApp', options.app, appConfig);
|
||||
} catch (e) {
|
||||
if (e instanceof Package.meteor.Meteor.Error &&
|
||||
e.error === 'already-exists') {
|
||||
if (e.errorType === 'Meteor.Error' && e.error === 'already-exists') {
|
||||
// Cool, it already exists. No problem. Just set the settings
|
||||
// if they were passed. We explicitly check for undefined
|
||||
// because we want to allow you to unset settings by passing
|
||||
|
||||
@@ -11,6 +11,7 @@ var ServiceConnection = require('./service-connection.js');
|
||||
var utils = require('./utils.js');
|
||||
var buildmessage = require('./buildmessage.js');
|
||||
var compiler = require('./compiler.js');
|
||||
var uniload = require('./uniload.js');
|
||||
|
||||
// Use uniload to load the packages that we need to open a connection to the
|
||||
// current package server and use minimongo in memory. We need the following
|
||||
@@ -18,12 +19,11 @@ var compiler = require('./compiler.js');
|
||||
//
|
||||
// meteor: base package and prerequsite for all others.
|
||||
// livedata: DDP client interface to make a connection to the package server.
|
||||
var getLoadedPackages = _.once(function () {
|
||||
var uniload = require('./uniload.js');
|
||||
var getLoadedPackages = function () {
|
||||
return uniload.load({
|
||||
packages: [ 'meteor', 'livedata', 'mongo-livedata']
|
||||
packages: [ 'meteor', 'livedata']
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Opens a DDP connection to a package server. Loads the packages needed for a
|
||||
// DDP connection, then calls DDP connect to the package server URL in config,
|
||||
@@ -441,7 +441,7 @@ exports.createAndPublishBuiltPackage = createAndPublishBuiltPackage;
|
||||
|
||||
exports.handlePackageServerConnectionError = function (error) {
|
||||
var Package = getLoadedPackages();
|
||||
if (error instanceof Package.meteor.Meteor.Error) {
|
||||
if (error.errorType === 'Meteor.Error') {
|
||||
process.stderr.write("Error connecting to package server");
|
||||
if (error.message) {
|
||||
process.stderr.write(": " + error.message);
|
||||
|
||||
@@ -17,7 +17,7 @@ var release = require('./release.js');
|
||||
// anywhere that may overlap with use of runLog.
|
||||
|
||||
|
||||
var getLoggingPackage = _.once(function () {
|
||||
var getLoggingPackage = function () {
|
||||
var Log = uniload.load({
|
||||
packages: ['logging']
|
||||
}).logging.Log;
|
||||
@@ -27,7 +27,7 @@ var getLoggingPackage = _.once(function () {
|
||||
Log.outputFormat = 'colored-text';
|
||||
|
||||
return Log;
|
||||
});
|
||||
};
|
||||
|
||||
var RunLog = function () {
|
||||
var self = this;
|
||||
|
||||
@@ -167,11 +167,11 @@ exports.deployWithNewEmail = function (s, email, appName) {
|
||||
return token;
|
||||
};
|
||||
|
||||
var getLoadedPackages = _.once(function () {
|
||||
var getLoadedPackages = function () {
|
||||
return uniload.load({
|
||||
packages: ['meteor', 'livedata']
|
||||
packages: ['livedata']
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var ddpConnect = function (url) {
|
||||
var DDP = getLoadedPackages().livedata.DDP;
|
||||
|
||||
Reference in New Issue
Block a user