UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

80 lines 12.3 kB
"use strict"; /* * 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 = exports.validateScratchOrgInfoForResume = void 0; const messages_1 = require("../messages"); const sfError_1 = require("../sfError"); const logger_1 = require("../logger/logger"); const scratchOrgCache_1 = require("./scratchOrgCache"); const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents"); const WORKSPACE_CONFIG_FILENAME = 'sfdx-project.json'; ; const messages = new messages_1.Messages('@salesforce/core', 'scratchOrgErrorCodes', new Map([["SignupFailedError", "The request to create a scratch org failed with error code: %s."], ["SignupFailedUnknownError", "An unknown server error occurred. Please try again. If you still see this error, contact Salesforce support for assistance. Include the information from 'sfdx force:data:record:get -s ScratchOrgInfo -i %s -u %s'."], ["SignupFailedActionError", "See https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_error_codes.htm for information on error code %s."], ["SignupUnexpectedError", "The request to create a scratch org returned an unexpected status"], ["StillInProgressError", "The scratch org is not ready yet (Status = %s)."], ["action.StillInProgress", "Wait for a few minutes, and then try the command again"], ["NoScratchOrgInfoError", "No ScratchOrgInfo object found in the Dev Hub you specified. Check that the ID and the Dev Hub are correct."], ["ScratchOrgDeletedError", "That scratch org has been deleted, so you can't connect to it anymore."], ["INVALID_ID_FIELD", "Provide a valid template ID, in the format 0TTxxxxxxxxxxxx."], ["T-0002", "We couldn\u2019t find a template or snapshot with the ID or name specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["T-0003", "The template specified in the scratch org definition is unapproved. Contact Salesforce Support to request template approval."], ["T-0004", "The Trialforce Source Organization (TSO) for the template doesn\u2019t exist or has expired."], ["S-1006", "Provide a valid email address in your scratch org definition or your %s file."], ["S-2006", "Provide a valid country code in your scratch org definition or your %s file."], ["S-1017", "Specify a namespace that\u2019s used by a release org associated with your Dev Hub org."], ["S-1018", "Provide a valid My Domain value. This value can\u2019t include double hyphens, end in a hyphen, include restricted words, or be more than 40 characters long."], ["S-1019", "The My Domain value you chose is already in use."], ["S-1026", "Provide a valid namespace value. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["S-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance."], ["SH-0001", "Can\u2019t create scratch org. Contact the source org admin to add your Dev Hub org ID to Setup > Org Shape. Then try again."], ["SH-0002", "Can\u2019t create scratch org. No org shape exists for the specified sourceOrg. Create an org shape and try again."], ["SH-0003", "Can\u2019t create scratch org from org shape. The org shape version is outdated. Recreate the org shape and try again."], ["C-1007", "The username provided to the org:create command is already in use. Run 'force:org:list --clean' to remove stale org authentications or create the org with a different username."], ["C-1015", "We encountered a problem while registering your My Domain value with the DNS provider. Please try again."], ["C-1016", "We encountered a problem while attempting to configure and approve the Connected App for your org. Verify the Connected App configuration with your Salesforce admin."], ["C-1017", "Provide a valid namespace prefix. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["C-1020", "We couldn't find a template with the ID specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["C-1027", "The template specified in the Scratch Definition isn\u2019t supported. Specify a generic edition (such as Developer or Enterprise), or specify a template ID."], ["C-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance"]])); const namedMessages = new messages_1.Messages('@salesforce/core', 'scratchOrgErrorCodes', new Map([["SignupFailedError", "The request to create a scratch org failed with error code: %s."], ["SignupFailedUnknownError", "An unknown server error occurred. Please try again. If you still see this error, contact Salesforce support for assistance. Include the information from 'sfdx force:data:record:get -s ScratchOrgInfo -i %s -u %s'."], ["SignupFailedActionError", "See https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_error_codes.htm for information on error code %s."], ["SignupUnexpectedError", "The request to create a scratch org returned an unexpected status"], ["StillInProgressError", "The scratch org is not ready yet (Status = %s)."], ["action.StillInProgress", "Wait for a few minutes, and then try the command again"], ["NoScratchOrgInfoError", "No ScratchOrgInfo object found in the Dev Hub you specified. Check that the ID and the Dev Hub are correct."], ["ScratchOrgDeletedError", "That scratch org has been deleted, so you can't connect to it anymore."], ["INVALID_ID_FIELD", "Provide a valid template ID, in the format 0TTxxxxxxxxxxxx."], ["T-0002", "We couldn\u2019t find a template or snapshot with the ID or name specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["T-0003", "The template specified in the scratch org definition is unapproved. Contact Salesforce Support to request template approval."], ["T-0004", "The Trialforce Source Organization (TSO) for the template doesn\u2019t exist or has expired."], ["S-1006", "Provide a valid email address in your scratch org definition or your %s file."], ["S-2006", "Provide a valid country code in your scratch org definition or your %s file."], ["S-1017", "Specify a namespace that\u2019s used by a release org associated with your Dev Hub org."], ["S-1018", "Provide a valid My Domain value. This value can\u2019t include double hyphens, end in a hyphen, include restricted words, or be more than 40 characters long."], ["S-1019", "The My Domain value you chose is already in use."], ["S-1026", "Provide a valid namespace value. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["S-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance."], ["SH-0001", "Can\u2019t create scratch org. Contact the source org admin to add your Dev Hub org ID to Setup > Org Shape. Then try again."], ["SH-0002", "Can\u2019t create scratch org. No org shape exists for the specified sourceOrg. Create an org shape and try again."], ["SH-0003", "Can\u2019t create scratch org from org shape. The org shape version is outdated. Recreate the org shape and try again."], ["C-1007", "The username provided to the org:create command is already in use. Run 'force:org:list --clean' to remove stale org authentications or create the org with a different username."], ["C-1015", "We encountered a problem while registering your My Domain value with the DNS provider. Please try again."], ["C-1016", "We encountered a problem while attempting to configure and approve the Connected App for your org. Verify the Connected App configuration with your Salesforce admin."], ["C-1017", "Provide a valid namespace prefix. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["C-1020", "We couldn't find a template with the ID specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["C-1027", "The template specified in the Scratch Definition isn\u2019t supported. Specify a generic edition (such as Developer or Enterprise), or specify a template ID."], ["C-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance"]])); // 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 validateScratchOrgInfoForResume = async ({ jobId, scratchOrgInfo, cache, hubUsername, }) => { if (!scratchOrgInfo?.Id || scratchOrgInfo.Status === 'Deleted') { // 1. scratch org info does not exist in that dev hub or has been deleted cache.unset(jobId); await cache.write(); throw scratchOrgInfo.Status === 'Deleted' ? namedMessages.createError('ScratchOrgDeletedError') : namedMessages.createError('NoScratchOrgInfoError'); } if (['New', 'Creating'].includes(scratchOrgInfo.Status)) { // 2. scratchOrgInfo exists, still isn't finished. Stays in cache for future attempts throw namedMessages.createError('StillInProgressError', [scratchOrgInfo.Status], ['action.StillInProgress']); } return (0, exports.checkScratchOrgInfoForErrors)(scratchOrgInfo, hubUsername); }; exports.validateScratchOrgInfoForResume = validateScratchOrgInfoForResume; const checkScratchOrgInfoForErrors = async (orgInfo, hubUsername) => { if (!orgInfo?.Id) { throw new sfError_1.SfError('No scratch org info found.', 'ScratchOrgInfoNotFound'); } if (orgInfo.Status === 'Active') { await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'available', scratchOrgInfo: orgInfo }); return orgInfo; } if (orgInfo.Status === 'Error' && orgInfo.ErrorCode) { await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id); const message = optionalErrorCodeMessage(orgInfo.ErrorCode, [WORKSPACE_CONFIG_FILENAME]); if (message) { throw new sfError_1.SfError(message, 'RemoteOrgSignupFailed', [ namedMessages.getMessage('SignupFailedActionError', [orgInfo.ErrorCode]), ]); } throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedError', [orgInfo.ErrorCode])); } if (orgInfo.Status === 'Error') { await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id); const logger = await logger_1.Logger.child('ScratchOrgErrorCodes'); // Maybe the request object can help the user somehow logger.error('No error code on signup error! Logging request.'); logger.error(orgInfo); throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedUnknownError', [orgInfo.Id, hubUsername]), 'signupFailedUnknown'); } throw new sfError_1.SfError(namedMessages.getMessage('SignupUnexpectedError'), 'UnexpectedSignupStatus'); }; exports.checkScratchOrgInfoForErrors = checkScratchOrgInfoForErrors; //# sourceMappingURL=scratchOrgErrorCodes.js.map