UNPKG

13.5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const sdk_1 = require("@cto.ai/sdk");
5const errorSource_1 = require("../constants/errorSource");
6const env_1 = require("../constants/env");
7const ErrorTemplate_1 = require("./ErrorTemplate");
8const utils_1 = require("../utils");
9const debug_1 = tslib_1.__importDefault(require("debug"));
10const debug = debug_1.default('ops:CustomErrors');
11const expectedSource = {
12 source: errorSource_1.errorSource.EXPECTED,
13};
14const { actionBlue, white, dim } = sdk_1.ux.colors;
15const problemContinues = `If the problem continues please contact us at: ${actionBlue(env_1.INTERCOM_EMAIL)}`;
16const tryAgainOrContact = `Please try again or contact ${actionBlue(env_1.INTERCOM_EMAIL)} and we'll do our best to help.`;
17class FileNotFoundError extends ErrorTemplate_1.ErrorTemplate {
18 constructor(err, path, file) {
19 super(white(`🤔 Looks like the file ${actionBlue(file)} wasn't found in path:\n ${actionBlue(path)}\n Please verify it exists and try again.`), err, expectedSource);
20 }
21}
22exports.FileNotFoundError = FileNotFoundError;
23class DockerBuildImageError extends ErrorTemplate_1.ErrorTemplate {
24 constructor(err) {
25 super(white('🤔 Looks like there was an error when building your image.\n Please check your Dockerfile and try again.'), err, expectedSource);
26 }
27}
28exports.DockerBuildImageError = DockerBuildImageError;
29class ConfigError extends ErrorTemplate_1.ErrorTemplate {
30 constructor(err) {
31 super(white(`❗️Uh-oh, we experienced a problem.\n Please try signing out and back in again.\n ${problemContinues}`), err, expectedSource);
32 }
33}
34exports.ConfigError = ConfigError;
35class CopyTemplateFilesError extends ErrorTemplate_1.ErrorTemplate {
36 constructor(err) {
37 super(white(`❗We couldn't copy the required files.\n Please check your directory permissions.\n ${tryAgainOrContact}`), err, expectedSource);
38 }
39}
40exports.CopyTemplateFilesError = CopyTemplateFilesError;
41class MandatoryParameter extends ErrorTemplate_1.ErrorTemplate {
42 constructor(err) {
43 super(white(`❗️Uh-oh, your request failed due to undefined parameters.\n ${tryAgainOrContact}`), err, expectedSource);
44 }
45}
46exports.MandatoryParameter = MandatoryParameter;
47class UndefinedParameter extends ErrorTemplate_1.ErrorTemplate {
48 constructor(err) {
49 super('Missing parameter', err);
50 }
51}
52exports.UndefinedParameter = UndefinedParameter;
53class UserUnauthorized extends ErrorTemplate_1.ErrorTemplate {
54 constructor(err) {
55 super(white("🤚 You don't have permissions for that action. Please try again."), err, expectedSource);
56 }
57}
58exports.UserUnauthorized = UserUnauthorized;
59class CouldNotCreateOp extends ErrorTemplate_1.ErrorTemplate {
60 constructor(err) {
61 super(white('😅 Uh-oh, this op already exists, please remove it try again.'), err, expectedSource);
62 }
63}
64exports.CouldNotCreateOp = CouldNotCreateOp;
65class CouldNotCreateWorkflow extends ErrorTemplate_1.ErrorTemplate {
66 constructor(err) {
67 super(white('😅 Uh-oh, this workflow already exists, please remove it try again.'), err, expectedSource);
68 }
69}
70exports.CouldNotCreateWorkflow = CouldNotCreateWorkflow;
71class CouldNotInitializeOp extends ErrorTemplate_1.ErrorTemplate {
72 constructor(err) {
73 super(white(`❗️Looks like a problem occurred initializing your Op / Workflow.\n ${tryAgainOrContact}`), err, expectedSource);
74 }
75}
76exports.CouldNotInitializeOp = CouldNotInitializeOp;
77class CouldNotGetRegistryToken extends ErrorTemplate_1.ErrorTemplate {
78 constructor(err) {
79 super(white('😅Call to registry/token failed, most likely due to invalid access token.'), err, expectedSource);
80 }
81}
82exports.CouldNotGetRegistryToken = CouldNotGetRegistryToken;
83class CouldNotMakeDir extends ErrorTemplate_1.ErrorTemplate {
84 constructor(err, path = '') {
85 super(white(`😅 Looks like we weren't able to create a config directory at:\n ${actionBlue(path)}\n Please check your permissions and try again.`), err, expectedSource);
86 }
87}
88exports.CouldNotMakeDir = CouldNotMakeDir;
89class InvalidTeamNameFormat extends ErrorTemplate_1.ErrorTemplate {
90 constructor(err) {
91 super(white(`❗ Sorry, that's an invalid team name. \n ❗ Team names may contain only letters (case-sensitive), numbers, dashes (-), and underscores (_).`), err, {
92 source: errorSource_1.errorSource.EXPECTED,
93 exit: false,
94 });
95 }
96}
97exports.InvalidTeamNameFormat = InvalidTeamNameFormat;
98class CouldNotGetLatestVersion extends ErrorTemplate_1.ErrorTemplate {
99 constructor(err) {
100 super('Call to check version failed, most likely due to internet connection.', err, {
101 source: errorSource_1.errorSource.EXPECTED,
102 exit: false,
103 });
104 }
105}
106exports.CouldNotGetLatestVersion = CouldNotGetLatestVersion;
107class APIError extends ErrorTemplate_1.ErrorTemplate {
108 constructor(err) {
109 super(white(`❗️ Looks like an API error occurred.\n ${tryAgainOrContact}`), err, expectedSource);
110 }
111}
112exports.APIError = APIError;
113class AnalyticsError extends ErrorTemplate_1.ErrorTemplate {
114 constructor(err) {
115 super('Analytics error occurred', err, { exit: false });
116 }
117}
118exports.AnalyticsError = AnalyticsError;
119class PermissionsError extends ErrorTemplate_1.ErrorTemplate {
120 constructor(err) {
121 super(white(`🤚 Uh-oh! You don't have permission to perform this action.\n Please review your system user permissions and try again.`), err, expectedSource);
122 }
123}
124exports.PermissionsError = PermissionsError;
125class InviteSendingInvite extends ErrorTemplate_1.ErrorTemplate {
126 constructor(err) {
127 super(white('😅 Uh-oh, the invite failed to send. Please try again.'), err, expectedSource);
128 }
129}
130exports.InviteSendingInvite = InviteSendingInvite;
131class InviteCodeInvalid extends ErrorTemplate_1.ErrorTemplate {
132 constructor(err) {
133 super(white("😅 Uh-oh, the invite code doesn't seem to be valid. Please check the code and try again."), err, expectedSource);
134 }
135}
136exports.InviteCodeInvalid = InviteCodeInvalid;
137class InvalidInputCharacter extends ErrorTemplate_1.ErrorTemplate {
138 constructor(fieldName) {
139 super(white(`❗ The ${fieldName} can only contain numbers, letters, -, or _'.`), undefined, expectedSource);
140 }
141}
142exports.InvalidInputCharacter = InvalidInputCharacter;
143class MissingRequiredArgument extends ErrorTemplate_1.ErrorTemplate {
144 constructor(command) {
145 super(white(`✋ This command requires an argument. Run ${utils_1.terminalText(`${command} --help`)} to learn more.`), undefined, expectedSource);
146 }
147}
148exports.MissingRequiredArgument = MissingRequiredArgument;
149class NoResultsFoundForDeletion extends ErrorTemplate_1.ErrorTemplate {
150 constructor(opOrWorkflow) {
151 super(white(`🤔 We couldn't find any matches for ${actionBlue(opOrWorkflow)}.\n Please check the name and try again.`), undefined, expectedSource);
152 }
153}
154exports.NoResultsFoundForDeletion = NoResultsFoundForDeletion;
155class DockerPublishNoImageFound extends ErrorTemplate_1.ErrorTemplate {
156 constructor(opName, teamName) {
157 super(white(`✋ We couldn't find an image for that ${actionBlue(opName)}.\n ⚙️ Please build this op for ${actionBlue(`${teamName}`)}: ${utils_1.terminalText(`ops build ${opName}`)}`), undefined, expectedSource);
158 }
159}
160exports.DockerPublishNoImageFound = DockerPublishNoImageFound;
161class NoLocalOpsFound extends ErrorTemplate_1.ErrorTemplate {
162 constructor() {
163 super(white(`💩 We couldn't find any ops in the ops.yml!`), undefined, expectedSource);
164 }
165}
166exports.NoLocalOpsFound = NoLocalOpsFound;
167class NoOpsFound extends ErrorTemplate_1.ErrorTemplate {
168 constructor(opName) {
169 super(white(`💩 We couldn't find any ops with the name ${opName}!`), undefined, expectedSource);
170 }
171}
172exports.NoOpsFound = NoOpsFound;
173class NoWorkflowsFound extends ErrorTemplate_1.ErrorTemplate {
174 constructor() {
175 super(white(`💩 We couldn't find any workflows in the ops.yml!`), undefined, expectedSource);
176 }
177}
178exports.NoWorkflowsFound = NoWorkflowsFound;
179class NoStepsFound extends ErrorTemplate_1.ErrorTemplate {
180 constructor() {
181 super(white(`💩 We couldn't find any workflow steps in the ops.yml!`), undefined, expectedSource);
182 }
183}
184exports.NoStepsFound = NoStepsFound;
185class InvalidStepsFound extends ErrorTemplate_1.ErrorTemplate {
186 constructor(step) {
187 super(white(`💩 Workflow step: ${step} is invalid!`), undefined, expectedSource);
188 }
189}
190exports.InvalidStepsFound = InvalidStepsFound;
191class ImageNotFoundError extends ErrorTemplate_1.ErrorTemplate {
192 constructor(imageName) {
193 super(white(`🤔 We couldn't find an image with the name ${actionBlue(imageName)}.\n Please select a different one and try again.`), undefined, expectedSource);
194 }
195}
196exports.ImageNotFoundError = ImageNotFoundError;
197class SignInError extends ErrorTemplate_1.ErrorTemplate {
198 constructor(err) {
199 super(white(`🤔 Sorry, we couldn’t find an account with that email or password.\n Forgot your password? Run ${utils_1.terminalText('ops account:reset')}`), err, expectedSource);
200 }
201}
202exports.SignInError = SignInError;
203class NoEmailForReset extends ErrorTemplate_1.ErrorTemplate {
204 constructor(err, email) {
205 super(white(`😞 Uh-oh, we couldn't find any user associated with ${actionBlue(email)}\n Please Check your email and try again.`), err, expectedSource);
206 }
207}
208exports.NoEmailForReset = NoEmailForReset;
209class ResetTokenError extends ErrorTemplate_1.ErrorTemplate {
210 constructor(err) {
211 super(white(`😅 Looks like there's an issue with that token.\n Please request a new token by running ${utils_1.terminalText('ops account:reset')}`), err, expectedSource);
212 }
213}
214exports.ResetTokenError = ResetTokenError;
215class SignUpError extends ErrorTemplate_1.ErrorTemplate {
216 constructor(err) {
217 super(white(`😅 We couldn't sign you up at this point in time.\n ${tryAgainOrContact}`), err, expectedSource);
218 }
219}
220exports.SignUpError = SignUpError;
221class ImageTagError extends ErrorTemplate_1.ErrorTemplate {
222 constructor(err) {
223 super('❗️ Could not tag image.', err);
224 }
225}
226exports.ImageTagError = ImageTagError;
227class ImagePushError extends ErrorTemplate_1.ErrorTemplate {
228 constructor(err) {
229 super('❗️ Could not push image.', err);
230 }
231}
232exports.ImagePushError = ImagePushError;
233class AlreadySignedOut extends ErrorTemplate_1.ErrorTemplate {
234 constructor() {
235 super(white(`🤷‍♂️ Looks like you are already signed out.\n Run ${utils_1.terminalText('ops account:signin')} to sign back into your account.`), undefined, expectedSource);
236 }
237}
238exports.AlreadySignedOut = AlreadySignedOut;
239class SignOutError extends ErrorTemplate_1.ErrorTemplate {
240 constructor(err) {
241 super(white(`😅 Uh-oh, we weren't able to sign out up at this point in time.\n ${tryAgainOrContact}`), err, expectedSource);
242 }
243}
244exports.SignOutError = SignOutError;
245class YamlPortError extends ErrorTemplate_1.ErrorTemplate {
246 constructor(badPort) {
247 super(white(`🤔 We're having trouble parsing the port: ${badPort}.\n ${dim('Please enter with the format')} ${actionBlue('{HostPort}:{InternalPort}')}${dim('. For example:')} ${actionBlue('3000:3000')}`), undefined, expectedSource);
248 }
249}
250exports.YamlPortError = YamlPortError;
251class SSOError extends ErrorTemplate_1.ErrorTemplate {
252 constructor(message) {
253 message && debug(message);
254 super(white(`🤔 We're having trouble signing you in. Please try running ${actionBlue('$ ops account:signin')} again!`), undefined, expectedSource);
255 }
256}
257exports.SSOError = SSOError;
258class TokenExpiredError extends ErrorTemplate_1.ErrorTemplate {
259 constructor() {
260 super(white(`\n⚠️ Sorry your session has expired. \n\n 👨‍💻 You can sign in with ${sdk_1.ux.colors.green('$')} ${sdk_1.ux.colors.callOutCyan('ops account:signin')}`), undefined, expectedSource);
261 }
262}
263exports.TokenExpiredError = TokenExpiredError;
264class CannotDeleteOps extends ErrorTemplate_1.ErrorTemplate {
265 constructor(err) {
266 super(white(`❗ Sorry, we cannot delete the op. \n\n Please verify that it is not being used in some other op.\n`), err, expectedSource);
267 }
268}
269exports.CannotDeleteOps = CannotDeleteOps;
270class InvalidOpName extends ErrorTemplate_1.ErrorTemplate {
271 constructor() {
272 super(white(`❗ Sorry, we cannot find that op. Please enter an op with the format:\n- ${sdk_1.ux.colors.bold('@teamName')}/${sdk_1.ux.colors.cyan('opName')}\n- ${sdk_1.ux.colors.cyan('opName')}: for ops you have in your team, or a folder in your current working directory`), undefined, expectedSource);
273 }
274}
275exports.InvalidOpName = InvalidOpName;
276class UnauthorizedtoAccessOp extends ErrorTemplate_1.ErrorTemplate {
277 constructor(err) {
278 super(white(`❗ Oops, seems like you do not have access to run this op!`), err, expectedSource);
279 }
280}
281exports.UnauthorizedtoAccessOp = UnauthorizedtoAccessOp;
282class IncompleteOpsYml extends ErrorTemplate_1.ErrorTemplate {
283 constructor(message) {
284 super(white(`❗ Sorry, we have difficulty parsing your ops.yml. ${message}`), undefined, expectedSource);
285 }
286}
287exports.IncompleteOpsYml = IncompleteOpsYml;