UNPKG

salesforce-alm

Version:

This package contains tools, and APIs, for an improved salesforce.com developer experience.

53 lines (51 loc) 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkScratchOrgInfoForErrors = void 0; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ const core_1 = require("@salesforce/core"); const consts = require("../core/constants"); core_1.Messages.importMessagesDirectory(__dirname); const messages = core_1.Messages.loadMessages('salesforce-alm', 'scratchorg_error_codes'); // getMessage will throw when the code isn't found // and we don't know whether a given code takes arguments or not const optionalErrorCodeMessage = (errorCode, args) => { try { // only apply args if message requires them let message = messages.getMessage(errorCode); if (message.includes('%s')) { message = messages.getMessage(errorCode, args); } return message; } catch { // generic error message return undefined; } }; exports.checkScratchOrgInfoForErrors = (orgInfo, hubUsername, logger) => { if (orgInfo.Status === 'Active') { return orgInfo; } if (orgInfo.Status === 'Error' && orgInfo.ErrorCode) { const message = optionalErrorCodeMessage(orgInfo.ErrorCode, [consts.WORKSPACE_CONFIG_FILENAME]); if (message) { throw new core_1.SfdxError(message, 'RemoteOrgSignupFailed', [ messages.getMessage('signupFailedAction', [orgInfo.ErrorCode]), ]); } throw new core_1.SfdxError(messages.getMessage('signupFailed', [orgInfo.ErrorCode])); } if (orgInfo.Status === 'Error') { // Maybe the request object can help the user somehow logger.error('No error code on signup error! Logging request.'); logger.error(orgInfo); throw new core_1.SfdxError(messages.getMessage('signupFailedUnknown', [orgInfo.Id, hubUsername]), 'signupFailedUnknown'); } throw new core_1.SfdxError(messages.getMessage('signupUnexpected'), 'UnexpectedSignupStatus'); }; //# sourceMappingURL=scratchOrgErrorCodes.js.map