1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | exports.checkScratchOrgInfoForErrors = exports.validateScratchOrgInfoForResume = void 0;
|
10 | const messages_1 = require("../messages");
|
11 | const sfError_1 = require("../sfError");
|
12 | const logger_1 = require("../logger");
|
13 | const scratchOrgCache_1 = require("./scratchOrgCache");
|
14 | const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents");
|
15 | const WORKSPACE_CONFIG_FILENAME = 'sfdx-project.json';
|
16 | messages_1.Messages.importMessagesDirectory(__dirname);
|
17 | const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgErrorCodes');
|
18 | const namedMessages = messages_1.Messages.load('@salesforce/core', 'scratchOrgErrorCodes', [
|
19 | 'SignupFailedActionError',
|
20 | 'SignupFailedUnknownError',
|
21 | 'SignupFailedError',
|
22 | 'SignupUnexpectedError',
|
23 | 'StillInProgressError',
|
24 | 'action.StillInProgress',
|
25 | 'ScratchOrgDeletedError',
|
26 | 'NoScratchOrgInfoError',
|
27 | ]);
|
28 |
|
29 |
|
30 | const optionalErrorCodeMessage = (errorCode, args) => {
|
31 | try {
|
32 |
|
33 | let message = messages.getMessage(errorCode);
|
34 | if (message.includes('%s')) {
|
35 | message = messages.getMessage(errorCode, args);
|
36 | }
|
37 | return message;
|
38 | }
|
39 | catch {
|
40 |
|
41 | return undefined;
|
42 | }
|
43 | };
|
44 | const validateScratchOrgInfoForResume = async ({ jobId, scratchOrgInfo, cache, hubUsername, }) => {
|
45 | if (!scratchOrgInfo || !scratchOrgInfo.Id || scratchOrgInfo.Status === 'Deleted') {
|
46 |
|
47 | cache.unset(jobId);
|
48 | await cache.write();
|
49 | throw scratchOrgInfo.Status === 'Deleted'
|
50 | ? namedMessages.createError('ScratchOrgDeletedError')
|
51 | : namedMessages.createError('NoScratchOrgInfoError');
|
52 | }
|
53 | if (['New', 'Creating'].includes(scratchOrgInfo.Status)) {
|
54 |
|
55 | throw namedMessages.createError('StillInProgressError', [scratchOrgInfo.Status], ['action.StillInProgress']);
|
56 | }
|
57 | return (0, exports.checkScratchOrgInfoForErrors)(scratchOrgInfo, hubUsername);
|
58 | };
|
59 | exports.validateScratchOrgInfoForResume = validateScratchOrgInfoForResume;
|
60 | const checkScratchOrgInfoForErrors = async (orgInfo, hubUsername) => {
|
61 | if (!orgInfo || !orgInfo.Id) {
|
62 | throw new sfError_1.SfError('No scratch org info found.', 'ScratchOrgInfoNotFound');
|
63 | }
|
64 | if (orgInfo.Status === 'Active') {
|
65 | await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'available', scratchOrgInfo: orgInfo });
|
66 | return orgInfo;
|
67 | }
|
68 | if (orgInfo.Status === 'Error' && orgInfo.ErrorCode) {
|
69 | await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id);
|
70 | const message = optionalErrorCodeMessage(orgInfo.ErrorCode, [WORKSPACE_CONFIG_FILENAME]);
|
71 | if (message) {
|
72 | throw new sfError_1.SfError(message, 'RemoteOrgSignupFailed', [
|
73 | namedMessages.getMessage('SignupFailedActionError', [orgInfo.ErrorCode]),
|
74 | ]);
|
75 | }
|
76 | throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedError', [orgInfo.ErrorCode]));
|
77 | }
|
78 | if (orgInfo.Status === 'Error') {
|
79 | await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id);
|
80 | const logger = await logger_1.Logger.child('ScratchOrgErrorCodes');
|
81 |
|
82 | logger.error('No error code on signup error! Logging request.');
|
83 | logger.error(orgInfo);
|
84 | throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedUnknownError', [orgInfo.Id, hubUsername]), 'signupFailedUnknown');
|
85 | }
|
86 | throw new sfError_1.SfError(namedMessages.getMessage('SignupUnexpectedError'), 'UnexpectedSignupStatus');
|
87 | };
|
88 | exports.checkScratchOrgInfoForErrors = checkScratchOrgInfoForErrors;
|
89 |
|
\ | No newline at end of file |