diff --git a/messages/connection.md b/messages/connection.md index 4643e4d3d5..d926ec0f3a 100644 --- a/messages/connection.md +++ b/messages/connection.md @@ -20,3 +20,11 @@ Connection has no instanceUrl. # noInstanceUrlError.actions Make sure the instanceUrl is set in your command or config. + +# noApiVersionsError + +Org failed to respond with its list of API versions. This is usually the result of domain changes like activating MyDomain or Enhanced Domains + +# noApiVersionsError.actions + +Re-authenticate to the org. diff --git a/src/org/connection.ts b/src/org/connection.ts index 7bc6ed03d6..a007797fc1 100644 --- a/src/org/connection.ts +++ b/src/org/connection.ts @@ -38,6 +38,7 @@ const messages = Messages.load('@salesforce/core', 'connection', [ 'incorrectAPIVersionError', 'domainNotFoundError', 'noInstanceUrlError', + 'noApiVersionsError', ]); const clientId = `sfdx toolbelt:${process.env.SFDX_SET_CLIENT_IDS || ''}`; @@ -227,6 +228,11 @@ export class Connection extends JSForceConnection await this.isResolvable(); type Versioned = { version: string }; const versions: Versioned[] = await this.request(`${this.instanceUrl}/services/data`); + // if the server doesn't return a list of versions, it's possibly a instanceUrl issue where the local file is out of date. + if (!Array.isArray(versions)) { + this.logger.debug(`server response for retrieveMaxApiVersion: ${versions}`); + throw messages.createError('noApiVersionsError'); + } this.logger.debug(`response for org versions: ${versions.map((item) => item.version).join(',')}`); const max = ensure(maxBy(versions, (version: Versioned) => version.version)); diff --git a/test/unit/org/connectionTest.ts b/test/unit/org/connectionTest.ts index 219c16b89a..aa71f7f334 100644 --- a/test/unit/org/connectionTest.ts +++ b/test/unit/org/connectionTest.ts @@ -51,6 +51,21 @@ describe('Connection', () => { }); }); + it('throws error when no valid API version', async () => { + const conn = await Connection.create({ authInfo: fromStub(testAuthInfoWithDomain) }); + + $$.SANDBOX.restore(); + $$.SANDBOX.stub(MyDomainResolver.prototype, 'resolve').resolves(TEST_IP); + $$.SANDBOX.stub(conn, 'isResolvable').resolves(true); + $$.SANDBOX.stub(JSForceConnection.prototype, 'request').resolves(''); + + try { + await shouldThrow(conn.retrieveMaxApiVersion()); + } catch (e) { + expect(e).to.have.property('name', 'NoApiVersionsError'); + } + }); + it('create() should throw on DNS errors', async () => { $$.SANDBOX.restore(); $$.SANDBOX.stub(MyDomainResolver.prototype, 'resolve').rejects({ name: DNS_ERROR_NAME }); diff --git a/yarn.lock b/yarn.lock index ad6c0a3923..0f276cc6e8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -158,17 +158,17 @@ integrity sha512-RSKRfYX20dyH+elbJK2uqAkVyucL+xXzhqlMD5/ZXx+dAAwpyB7HsvnHe/ZUGOF+xLr5Wx9/JoXVTj6BQE2/oA== "@babel/runtime-corejs3@^7.12.5": - version "7.18.9" - resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.18.9.tgz#7bacecd1cb2dd694eacd32a91fcf7021c20770ae" - integrity sha512-qZEWeccZCrHA2Au4/X05QW5CMdm4VjUDCrGq5gf1ZDcM4hRqreKrtwAn7yci9zfgAS9apvnsFXiGBHBAxZdK9A== + version "7.19.1" + resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.19.1.tgz#f0cbbe7edda7c4109cd253bb1dee99aba4594ad9" + integrity sha512-j2vJGnkopRzH+ykJ8h68wrHnEUmtK//E723jjixiAl/PPf6FhqY/vYRcMVlNydRKQjQsTsYEjpx+DZMIvnGk/g== dependencies: - core-js-pure "^3.20.2" + core-js-pure "^3.25.1" regenerator-runtime "^0.13.4" "@babel/runtime@^7.12.5": - version "7.18.9" - resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.18.9.tgz#b4fcfce55db3d2e5e080d2490f608a3b9f407f4a" - integrity sha512-lkqXDcvlFT5rvEjiu6+QYO+1GXrEHRo2LOtS7E4GtX5ESIZOgepqsZBVIj6Pv+a6zqsya9VCgiK1KAK4BvJDAw== + version "7.19.0" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.19.0.tgz#22b11c037b094d27a8a2504ea4dcff00f50e2259" + integrity sha512-eR8Lo9hnDS7tqkO7NsV+mKvCmv5boaXFSZ70DnfhcgiEne8hv9oCEd36Klw74EtizEqLsy4YnW8UWwpBVolHZA== dependencies: regenerator-runtime "^0.13.4" @@ -1833,15 +1833,15 @@ copy-descriptor@^0.1.0: resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" integrity sha512-XgZ0pFcakEUlbwQEVNg3+QAis1FyTL3Qel9FYy8pSkQqoG3PNoT0bOCQtOXcOkur21r2Eq2kI+IE+gsmAEVlYw== -core-js-pure@^3.20.2: - version "3.23.5" - resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.23.5.tgz#23daaa9af9230e50f10b0fa4b8e6b87402be4c33" - integrity sha512-8t78LdpKSuCq4pJYCYk8hl7XEkAX+BP16yRIwL3AanTksxuEf7CM83vRyctmiEL8NDZ3jpUcv56fk9/zG3aIuw== +core-js-pure@^3.25.1: + version "3.25.4" + resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.25.4.tgz#e8642cef4f4246a4e7c15280f5e3926118fff84b" + integrity sha512-qRbgm0ADrsNTU66UcW47YMJjXm+ShhUP2gkoEoAShT2BHO3cb5gGqLtmWpjnM6Wx9h5hMSF4uZ+jEV/8+4KCsw== core-js@^3.6.4: - version "3.23.5" - resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.23.5.tgz#1f82b0de5eece800827a2f59d597509c67650475" - integrity sha512-7Vh11tujtAZy82da4duVreQysIoO2EvVrur7y6IzZkH1IHPSekuDi8Vuw1+YKjkbfWLRD7Nc9ICQ/sIUDutcyg== + version "3.25.4" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.25.4.tgz#76f6bc330a79aafbaf77e9645293351ea5d09b5b" + integrity sha512-JDLxg61lFPFYQ7U0HKoyKwVUV63VbbVTb/K73Yf+k4Mf4ZBZxCjfyrWZjTk1ZM7ZrgFSqhSIOmuzYAxG2f/reQ== core-util-is@~1.0.0: version "1.0.3" @@ -3731,9 +3731,9 @@ jsesc@^2.5.1: integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== jsforce@beta: - version "2.0.0-beta.18" - resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.18.tgz#2791a2e6ec15d4d8b41f0782e23b833f5dbe5678" - integrity sha512-9IKv3M/U/FCdL6G8WlFqWiBTvLx1TRmGW+JhcSWHZb0YlMLHiGNVymvLyPsvRfO9sNP6VR3A5AIntqD+UsDKkQ== + version "2.0.0-beta.19" + resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.19.tgz#4a136b88d6a9f6668714c4ccbb0acd55e46ea493" + integrity sha512-WdF6hs7kukXNGvp/VRhu2DngldgiBBorsc2WA5us08oJGbEIPwn/itqYJWKJ+rfPXepz5JbkWQd48XHGjqmPpw== dependencies: "@babel/runtime" "^7.12.5" "@babel/runtime-corejs3" "^7.12.5"