From 08a6fa99fde286279498d6fab9959361b69a3ff3 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Sun, 17 Aug 2014 23:37:38 -0700 Subject: [PATCH] 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. --- tools/auth.js | 9 ++++----- tools/deploy-galaxy.js | 7 +++---- tools/package-client.js | 10 +++++----- tools/run-log.js | 4 ++-- tools/test-utils.js | 6 +++--- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/tools/auth.js b/tools/auth.js index 8cab010bb3..b6d43251b0 100644 --- a/tools/auth.js +++ b/tools/auth.js @@ -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; } } diff --git a/tools/deploy-galaxy.js b/tools/deploy-galaxy.js index 5eb1e3513d..016e5cd836 100644 --- a/tools/deploy-galaxy.js +++ b/tools/deploy-galaxy.js @@ -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 diff --git a/tools/package-client.js b/tools/package-client.js index dbeb01c230..dff01354e5 100644 --- a/tools/package-client.js +++ b/tools/package-client.js @@ -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); diff --git a/tools/run-log.js b/tools/run-log.js index 4db60f77ec..f638a2f7f9 100644 --- a/tools/run-log.js +++ b/tools/run-log.js @@ -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; diff --git a/tools/test-utils.js b/tools/test-utils.js index 9bea1296fa..50d05f3164 100644 --- a/tools/test-utils.js +++ b/tools/test-utils.js @@ -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;