From 4fabb2972cc839476c56be928e556f2a7ef19f4d Mon Sep 17 00:00:00 2001 From: matheusccastro Date: Sat, 7 Sep 2024 01:46:47 -0300 Subject: [PATCH] fix: add missing `await` calls --- packages/mongo/mongo_driver.js | 2 +- packages/service-configuration/package.js | 2 +- .../service_configuration_server.js | 64 +++++++++---------- tools/cli/commands-packages.js | 21 +++--- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/packages/mongo/mongo_driver.js b/packages/mongo/mongo_driver.js index 594b61d1650..6f4092ad7c2 100644 --- a/packages/mongo/mongo_driver.js +++ b/packages/mongo/mongo_driver.js @@ -1059,7 +1059,7 @@ class AsynchronousCursor { // the Mongo->Meteor type replacement). async _rawNextObjectPromise() { try { - return this._dbCursor.next(); + return (await this._dbCursor.next()); } catch (e) { console.error(e); } diff --git a/packages/service-configuration/package.js b/packages/service-configuration/package.js index 43e82a48883..611087dccd5 100644 --- a/packages/service-configuration/package.js +++ b/packages/service-configuration/package.js @@ -1,6 +1,6 @@ Package.describe({ summary: 'Manage the configuration for third-party services', - version: '1.3.5', + version: '1.3.6', }); Package.onUse(function(api) { diff --git a/packages/service-configuration/service_configuration_server.js b/packages/service-configuration/service_configuration_server.js index 087f8cd6abc..228c2d2b585 100644 --- a/packages/service-configuration/service_configuration_server.js +++ b/packages/service-configuration/service_configuration_server.js @@ -1,41 +1,41 @@ import { Meteor } from 'meteor/meteor'; -// Only one configuration should ever exist for each service. -// A unique index helps avoid various race conditions which could -// otherwise lead to an inconsistent database state (when there are multiple -// configurations for a single service, which configuration is correct?) -try { - ServiceConfiguration.configurations.createIndexAsync( - { service: 1 }, - { unique: true } - ); -} catch (err) { - console.error( - 'The service-configuration package persists configuration in the ' + - 'meteor_accounts_loginServiceConfiguration collection in MongoDB. As ' + - 'each service should have exactly one configuration, Meteor ' + - 'automatically creates a MongoDB index with a unique constraint on the ' + - ' meteor_accounts_loginServiceConfiguration collection. The ' + - 'createIndex command which creates that index is failing.\n\n' + - 'Meteor versions before 1.0.4 did not create this index. If you recently ' + - 'upgraded and are seeing this error message for the first time, please ' + - 'check your meteor_accounts_loginServiceConfiguration collection for ' + - 'multiple configuration entries for the same service and delete ' + - 'configuration entries until there is no more than one configuration ' + - 'entry per service.\n\n' + - 'If the meteor_accounts_loginServiceConfiguration collection looks ' + - 'fine, the createIndex command is failing for some other reason.\n\n' + - 'For more information on this history of this issue, please see ' + - 'https://github.com/meteor/meteor/pull/3514.\n' - ); - throw err; -} +Meteor.startup(async () => { + // Only one configuration should ever exist for each service. + // A unique index helps avoid various race conditions which could + // otherwise lead to an inconsistent database state (when there are multiple + // configurations for a single service, which configuration is correct?) + try { + await ServiceConfiguration.configurations.createIndexAsync( + { service: 1 }, + { unique: true } + ); + } catch (err) { + console.error( + 'The service-configuration package persists configuration in the ' + + 'meteor_accounts_loginServiceConfiguration collection in MongoDB. As ' + + 'each service should have exactly one configuration, Meteor ' + + 'automatically creates a MongoDB index with a unique constraint on the ' + + ' meteor_accounts_loginServiceConfiguration collection. The ' + + 'createIndex command which creates that index is failing.\n\n' + + 'Meteor versions before 1.0.4 did not create this index. If you recently ' + + 'upgraded and are seeing this error message for the first time, please ' + + 'check your meteor_accounts_loginServiceConfiguration collection for ' + + 'multiple configuration entries for the same service and delete ' + + 'configuration entries until there is no more than one configuration ' + + 'entry per service.\n\n' + + 'If the meteor_accounts_loginServiceConfiguration collection looks ' + + 'fine, the createIndex command is failing for some other reason.\n\n' + + 'For more information on this history of this issue, please see ' + + 'https://github.com/meteor/meteor/pull/3514.\n' + ); + throw err; + } -Meteor.startup(() => { const settings = Meteor.settings?.packages?.['service-configuration']; if (!settings) return; for (const key of Object.keys(settings)) { - ServiceConfiguration.configurations.upsertAsync( + await ServiceConfiguration.configurations.upsertAsync( { service: key }, { $set: settings[key], diff --git a/tools/cli/commands-packages.js b/tools/cli/commands-packages.js index e580246c480..77ab11b4309 100644 --- a/tools/cli/commands-packages.js +++ b/tools/cli/commands-packages.js @@ -2851,7 +2851,7 @@ main.registerCommand({ } try { - var conn = packageClient.loggedInPackagesConnection(); + var conn = await packageClient.loggedInPackagesConnection(); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1; @@ -2951,8 +2951,9 @@ main.registerCommand({ versions = await catalog.official.getSortedVersions(name); } + var conn; try { - var conn = await packageClient.loggedInPackagesConnection(); + conn = await packageClient.loggedInPackagesConnection(); } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1; @@ -2961,16 +2962,16 @@ main.registerCommand({ try { var status = options.success ? "successfully" : "unsuccessfully"; // XXX: This should probably use progress bars instead. - _.each(versions, function (version) { + for (const version of versions) { Console.rawInfo( - "Setting " + name + "@" + version + " as " + - status + " migrated ...\n"); - packageClient.callPackageServer( - conn, - '_changeVersionMigrationStatus', - name, version, !options.success); + "Setting " + name + "@" + version + " as " + + status + " migrated ...\n"); + await packageClient.callPackageServer( + conn, + '_changeVersionMigrationStatus', + name, version, !options.success); Console.info("done."); - }); + } } catch (err) { packageClient.handlePackageServerConnectionError(err); return 1;