@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
56 lines • 2.46 kB
JavaScript
;
/*
* Copyright (c) 2021, 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkScratchOrgInfoForErrors = void 0;
const messages_1 = require("./messages");
const sfdxError_1 = require("./sfdxError");
const WORKSPACE_CONFIG_FILENAME = 'sfdx-project.json';
messages_1.Messages.importMessagesDirectory(__dirname);
const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgErrorCodes');
// 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;
}
};
const checkScratchOrgInfoForErrors = (orgInfo, hubUsername, logger) => {
if (!orgInfo) {
throw new sfdxError_1.SfdxError('No scratch org info found.', 'ScratchOrgInfoNotFound');
}
if (orgInfo.Status === 'Active') {
return orgInfo;
}
if (orgInfo.Status === 'Error' && orgInfo.ErrorCode) {
const message = optionalErrorCodeMessage(orgInfo.ErrorCode, [WORKSPACE_CONFIG_FILENAME]);
if (message) {
throw new sfdxError_1.SfdxError(message, 'RemoteOrgSignupFailed', [
messages.getMessage('signupFailedAction', [orgInfo.ErrorCode]),
]);
}
throw new sfdxError_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 sfdxError_1.SfdxError(messages.getMessage('signupFailedUnknown', [orgInfo.Id, hubUsername]), 'signupFailedUnknown');
}
throw new sfdxError_1.SfdxError(messages.getMessage('signupUnexpected'), 'UnexpectedSignupStatus');
};
exports.checkScratchOrgInfoForErrors = checkScratchOrgInfoForErrors;
//# sourceMappingURL=scratchOrgErrorCodes.js.map