Skip to content

Commit 9cb92a0

Browse files
reeshika-hharshithad0703
authored andcommitted
Merge pull request #2257 from contentstack/fix/DX-3458-error-msg-improve
improved error messages
1 parent 8a6564d commit 9cb92a0

File tree

112 files changed

+864
-835
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+864
-835
lines changed

package-lock.json

Lines changed: 424 additions & 409 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-auth/src/commands/auth/login.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
5555
log.debug('LoginCommand run method started', this.contextDetails);
5656

5757
try {
58-
log.debug('Initializing management API client', this.contextDetails);
58+
log.debug('Initializing the Management API client.', this.contextDetails);
5959
const managementAPIClient = await managementSDKClient({ host: this.cmaHost, skipTokenValidity: true });
60-
log.debug('Management API client initialized successfully', this.contextDetails);
60+
log.debug('Management API client initialized successfully.', this.contextDetails);
6161

6262
const { flags: loginFlags } = await this.parse(LoginCommand);
63-
log.debug('Token add flags parsed', { ...this.contextDetails, flags: loginFlags });
63+
log.debug('Token add flags parsed.', { ...this.contextDetails, flags: loginFlags });
6464

6565
authHandler.client = managementAPIClient;
6666
log.debug('Auth handler client set', this.contextDetails);
@@ -86,7 +86,7 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
8686
await this.login(username, password);
8787
}
8888
} catch (error) {
89-
log.debug('Login command failed', {
89+
log.debug('Login failed.', {
9090
...this.contextDetails,
9191
error,
9292
});
@@ -116,26 +116,26 @@ export default class LoginCommand extends BaseCommand<typeof LoginCommand> {
116116
}
117117

118118
const user: User = await authHandler.login(username, password, tfaToken);
119-
log.debug('Auth handler login completed', {
119+
log.debug('Auth handler login completed.', {
120120
...this.contextDetails,
121121
hasUser: !!user,
122122
hasAuthToken: !!user?.authtoken,
123123
userEmail: user?.email,
124124
});
125125

126126
if (typeof user !== 'object' || !user.authtoken || !user.email) {
127-
log.debug('Login failed - invalid user response', { ...this.contextDetails, user });
128-
throw new CLIError('Failed to login - invalid response');
127+
log.debug('Login failed: Invalid user response', { ...this.contextDetails, user });
128+
throw new CLIError('Login failed: Invalid response.');
129129
}
130130

131-
log.debug('Setting config data for basic auth', this.contextDetails);
131+
log.debug('Setting configuration data for basic authentication.', this.contextDetails);
132132
await oauthHandler.setConfigData('basicAuth', user);
133-
log.debug('Config data set successfully', this.contextDetails);
133+
log.debug('Configuration data set successfully.', this.contextDetails);
134134

135135
log.success(messageHandler.parse('CLI_AUTH_LOGIN_SUCCESS'), this.contextDetails);
136-
log.debug('Login process completed successfully', this.contextDetails);
136+
log.debug('Login completed successfully.', this.contextDetails);
137137
} catch (error) {
138-
log.debug('Login process failed', { ...this.contextDetails, error });
138+
log.debug('Login failed.', { ...this.contextDetails, error });
139139
throw error;
140140
}
141141
}

packages/contentstack-auth/src/commands/auth/logout.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default class LogoutCommand extends BaseCommand<typeof LogoutCommand> {
6161
}
6262

6363
try {
64-
log.debug('Initializing management API client for logout', this.contextDetails);
64+
log.debug('Initializing the Management API client for logout.', this.contextDetails);
6565
const managementAPIClient = await managementSDKClient({ host: this.cmaHost, skipTokenValidity: true });
6666
log.debug('Management API client initialized successfully', this.contextDetails);
6767

@@ -75,9 +75,9 @@ export default class LogoutCommand extends BaseCommand<typeof LogoutCommand> {
7575
if (await oauthHandler.isAuthorisationTypeBasic()) {
7676
log.debug('Using basic authentication for logout', this.contextDetails);
7777
const authToken = configHandler.get('authtoken');
78-
log.debug('Retrieved auth token for logout', { ...this.contextDetails, hasAuthToken: !!authToken });
78+
log.debug('Authentication token retrieved for logout.', { ...this.contextDetails, hasAuthToken: !!authToken });
7979
await authHandler.logout(authToken);
80-
log.debug('Basic auth logout completed', this.contextDetails);
80+
log.debug('Basic authentication logout completed.', this.contextDetails);
8181
} else if (await oauthHandler.isAuthorisationTypeOAuth()) {
8282
log.debug('Using OAuth authentication for logout', this.contextDetails);
8383
await oauthHandler.oauthLogout();
@@ -86,7 +86,7 @@ export default class LogoutCommand extends BaseCommand<typeof LogoutCommand> {
8686

8787
cliux.loader('');
8888
log.success(messageHandler.parse('CLI_AUTH_LOGOUT_SUCCESS'), this.contextDetails);
89-
log.debug('Logout process completed successfully', this.contextDetails);
89+
log.debug('Logout completed successfully.', this.contextDetails);
9090
} else {
9191
log.debug('User not confirmed or not authenticated, skipping logout', {
9292
...this.contextDetails,
@@ -96,14 +96,14 @@ export default class LogoutCommand extends BaseCommand<typeof LogoutCommand> {
9696
log.success(messageHandler.parse('CLI_AUTH_LOGOUT_ALREADY'), this.contextDetails);
9797
}
9898
} catch (error) {
99-
log.debug('Logout command failed', { ...this.contextDetails, error: error.message });
99+
log.debug('Logout failed.', { ...this.contextDetails, error: error.message });
100100
cliux.print('CLI_AUTH_LOGOUT_FAILED', { color: 'yellow' });
101101
handleAndLogError(error, { ...this.contextDetails });
102102
} finally {
103103
if (confirm === true) {
104-
log.debug('Setting config data for logout', this.contextDetails);
104+
log.debug('Setting configuration data for logout.', this.contextDetails);
105105
await oauthHandler.setConfigData('logout');
106-
log.debug('Config data set for logout', this.contextDetails);
106+
log.debug('Configuration data set for logout.', this.contextDetails);
107107
}
108108
}
109109
}

packages/contentstack-auth/src/commands/auth/tokens/add.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
8282
'auth:tokens:add [-a <value>] [--delivery] [--management] [-e <value>] [-k <value>] [-y] [--token <value>]';
8383

8484
async run(): Promise<any> {
85-
log.debug('TokensAddCommand run method started', this.contextDetails);
85+
log.debug('TokensAddCommand run method started.', this.contextDetails);
8686
this.contextDetails.module = 'tokens-add';
8787

8888
const { flags: addTokenFlags } = await this.parse(TokensAddCommand);
89-
log.debug('Token add flags parsed', { ...this.contextDetails, flags: addTokenFlags });
89+
log.debug('Token add flags parsed.', { ...this.contextDetails, flags: addTokenFlags });
9090

9191
let isAliasExist = false;
9292
const skipAliasReplaceConfirmation = addTokenFlags.force || addTokenFlags.yes;
@@ -141,7 +141,7 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
141141

142142
if (!shouldAliasReplace) {
143143
log.debug('User declined alias replacement, exiting', this.contextDetails);
144-
log.info('Exiting from the process of replacing the token', this.contextDetails);
144+
log.info('Exiting the token replacement process.', this.contextDetails);
145145
cliux.print('CLI_AUTH_EXIT_PROCESS');
146146
return;
147147
}
@@ -150,13 +150,13 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
150150
if (!apiKey) {
151151
log.debug('No API key provided, requesting user input', this.contextDetails);
152152
apiKey = await cliux.inquire({ type: 'input', message: 'CLI_AUTH_TOKENS_ADD_ENTER_API_KEY', name: 'apiKey' });
153-
log.debug('API key obtained', { ...this.contextDetails, hasApiKey: !!apiKey });
153+
log.debug('API key obtained.', { ...this.contextDetails, hasApiKey: !!apiKey });
154154
}
155155

156156
if (!token) {
157157
log.debug('No token provided, requesting user input', this.contextDetails);
158158
token = await cliux.inquire({ type: 'input', message: 'CLI_AUTH_TOKENS_ADD_ENTER_TOKEN', name: 'token' });
159-
log.debug('Token obtained', { ...this.contextDetails, hasToken: !!token });
159+
log.debug('Token obtained.', { ...this.contextDetails, hasToken: !!token });
160160
}
161161

162162
if (isDelivery && !environment) {
@@ -183,12 +183,12 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
183183
// FIXME - Once the SDK refresh token issue is resolved, need to revert this back to SDK call
184184
const httpClient = new HttpClient({ headers: { api_key: apiKey, authorization: token } });
185185

186-
log.debug('Making management token validation API call', this.contextDetails);
186+
log.debug('Making management token validation API call.', this.contextDetails);
187187
const response = (await httpClient.get(`https://${this.cmaHost}/v3/environments?limit=1`)).data;
188-
log.debug('Management token validation response received', { ...this.contextDetails, response });
188+
log.debug('Management token validation response received.', { ...this.contextDetails, response });
189189

190190
if (response?.error_code === 105) {
191-
log.debug('Management token validation failed - invalid token', this.contextDetails);
191+
log.debug('Management token validation failed: invalid token.', this.contextDetails);
192192
throw new Error(messageHandler.parse('CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN'));
193193
} else if (response?.error_message) {
194194
log.debug('Management token validation failed with error message', {
@@ -197,7 +197,7 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
197197
});
198198
throw new Error(response.error_message);
199199
}
200-
log.debug('Management token validation successful', this.contextDetails);
200+
log.debug('Management token validation successful.', this.contextDetails);
201201
}
202202

203203
log.debug('Saving token to configuration', {
@@ -208,23 +208,23 @@ export default class TokensAddCommand extends BaseCommand<typeof TokensAddComman
208208
});
209209
if (isManagement) {
210210
configHandler.set(`${configKeyTokens}.${alias}`, { token, apiKey, type });
211-
log.debug('Management token saved to configuration', this.contextDetails);
211+
log.debug('Management token saved to configuration.', this.contextDetails);
212212
} else {
213213
configHandler.set(`${configKeyTokens}.${alias}`, { token, apiKey, environment, type });
214-
log.debug('Delivery token saved to configuration', this.contextDetails);
214+
log.debug('Delivery token saved to configuration.', this.contextDetails);
215215
}
216216

217217
if (isAliasExist) {
218-
log.debug('Token replaced successfully', this.contextDetails);
218+
log.debug('Token replaced successfully.', this.contextDetails);
219219
cliux.success('CLI_AUTH_TOKENS_ADD_REPLACE_SUCCESS');
220220
} else {
221-
log.debug('Token added successfully', this.contextDetails);
221+
log.debug('Token added successfully.', this.contextDetails);
222222
cliux.success('CLI_AUTH_TOKENS_ADD_SUCCESS');
223223
}
224224

225-
log.debug('Token add process completed successfully', this.contextDetails);
225+
log.debug('Token addition process completed successfully.', this.contextDetails);
226226
} catch (error) {
227-
log.debug('Token add process failed', { ...this.contextDetails, error });
227+
log.debug('Token addition process failed.', { ...this.contextDetails, error });
228228
cliux.print('CLI_AUTH_TOKENS_ADD_FAILED', { color: 'yellow' });
229229
handleAndLogError(error, { ...this.contextDetails });
230230
}

packages/contentstack-auth/src/commands/auth/tokens/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ export default class TokensListCommand extends BaseCommand<typeof TokensListComm
2323
]); // use the cli table flags as it displays tokens in table
2424

2525
async run(): Promise<any> {
26-
log.debug('TokensListCommand run method started', this.contextDetails);
26+
log.debug('TokensListCommand run method started.', this.contextDetails);
2727
this.contextDetails.module = 'tokens-list';
2828

2929
try {
30-
log.debug('Retrieving tokens from configuration', this.contextDetails);
30+
log.debug('Retrieving tokens from configuration.', this.contextDetails);
3131
const managementTokens = configHandler.get('tokens');
32-
log.debug('Tokens retrieved from configuration', {...this.contextDetails, tokenCount: managementTokens ? Object.keys(managementTokens).length : 0 });
32+
log.debug('Tokens retrieved from configuration.', {...this.contextDetails, tokenCount: managementTokens ? Object.keys(managementTokens).length : 0 });
3333

3434
const tokens: Record<string, unknown>[] = [];
3535
if (managementTokens && Object.keys(managementTokens).length > 0) {
36-
log.debug('Processing tokens for display', this.contextDetails);
36+
log.debug('Processing tokens for display.', this.contextDetails);
3737
Object.keys(managementTokens).forEach(function (item) {
3838
tokens.push({
3939
alias: item,
@@ -46,7 +46,7 @@ export default class TokensListCommand extends BaseCommand<typeof TokensListComm
4646
});
4747

4848
const { flags } = await this.parse(TokensListCommand);
49-
log.debug('Tokens list flags parsed', {...this.contextDetails, flags });
49+
log.debug('Token list flags parsed.', {...this.contextDetails, flags });
5050

5151
const headers = [
5252
{
@@ -66,17 +66,17 @@ export default class TokensListCommand extends BaseCommand<typeof TokensListComm
6666
},
6767
];
6868

69-
log.debug('Displaying tokens table', {...this.contextDetails, tokenCount: tokens.length });
69+
log.debug('Displaying token table.', {...this.contextDetails, tokenCount: tokens.length });
7070
cliux.table(headers, tokens, flags as TableFlags);
71-
log.debug('Tokens table displayed successfully', this.contextDetails);
71+
log.debug('Token table displayed successfully.', this.contextDetails);
7272
} else {
73-
log.debug('No tokens found in configuration', this.contextDetails);
73+
log.debug('No tokens found in configuration.', this.contextDetails);
7474
cliux.print('CLI_AUTH_TOKENS_LIST_NO_TOKENS');
7575
}
7676

77-
log.debug('Tokens list command completed successfully', this.contextDetails);
77+
log.debug('Token list command completed successfully.', this.contextDetails);
7878
} catch (error) {
79-
log.debug('Tokens list command failed', {...this.contextDetails, error });
79+
log.debug('Token list command failed.', {...this.contextDetails, error });
8080
cliux.print('CLI_AUTH_TOKENS_LIST_FAILED', { color: 'yellow' });
8181
handleAndLogError(error, { ...this.contextDetails });
8282
}

packages/contentstack-auth/src/commands/auth/tokens/remove.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
1414
this.contextDetails.module = 'tokens-remove';
1515

1616
const { flags: removeTokenFlags } = await this.parse(TokensRemoveCommand);
17-
log.debug('Token remove flags parsed', {...this.contextDetails, flags: removeTokenFlags });
17+
log.debug('Token removal flags parsed.', {...this.contextDetails, flags: removeTokenFlags });
1818

1919
const alias = removeTokenFlags.alias;
2020
const ignore = removeTokenFlags.ignore;
21-
log.debug('Token removal parameters', {...this.contextDetails, alias, ignore });
21+
log.debug('Token removal parameters set.', {...this.contextDetails, alias, ignore });
2222

2323
try {
24-
log.debug('Retrieving token from configuration', {...this.contextDetails, alias });
24+
log.debug('Retrieving token from configuration.', {...this.contextDetails, alias });
2525
const token = configHandler.get(`tokens.${alias}`);
26-
log.debug('Token retrieved from configuration', {...this.contextDetails, hasToken: !!token, tokenType: token?.type });
26+
log.debug('Token retrieved from configuration.', {...this.contextDetails, hasToken: !!token, tokenType: token?.type });
2727

2828
const tokens = configHandler.get('tokens');
29-
log.debug('All tokens retrieved from configuration', {...this.contextDetails, tokenCount: tokens ? Object.keys(tokens).length : 0 });
29+
log.debug('All tokens retrieved from configuration.', {...this.contextDetails, tokenCount: tokens ? Object.keys(tokens).length : 0 });
3030

3131
const tokenOptions: Array<string> = [];
3232

3333
if (token || ignore) {
34-
log.debug('Token found or ignore flag set, proceeding with removal', {...this.contextDetails, hasToken: !!token, ignore });
34+
log.debug('Token found, or ignore flag set.', {...this.contextDetails, hasToken: !!token, ignore });
3535
configHandler.delete(`tokens.${alias}`);
36-
log.debug('Token removed from configuration', {...this.contextDetails, alias });
36+
log.debug('Token removed from configuration.', {...this.contextDetails, alias });
3737
return cliux.success(`CLI_AUTH_TOKENS_REMOVE_SUCCESS`);
3838
}
3939

4040
if (tokens && Object.keys(tokens).length > 0) {
41-
log.debug('Building token options for user selection', this.contextDetails);
41+
log.debug('Building token options for user selection.', this.contextDetails);
4242
Object.keys(tokens).forEach(function (item) {
4343
const tokenOption = `${item}: ${tokens[item].token} : ${tokens[item].apiKey}${
4444
tokens[item].environment ? ' : ' + tokens[item].environment + ' ' : ''
@@ -48,11 +48,11 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
4848
});
4949
log.debug(`Token options built: ${tokenOptions.length} options`, this.contextDetails);
5050
} else {
51-
log.debug('No tokens found in configuration', this.contextDetails);
51+
log.debug('No tokens found in configuration.', this.contextDetails);
5252
return cliux.print('CLI_AUTH_TOKENS_NOT_FOUND');
5353
}
5454

55-
log.debug('Requesting user to select tokens for removal', this.contextDetails);
55+
log.debug('Requesting user to select tokens for removal.', this.contextDetails);
5656
const selectedTokens: Array<any> = await cliux.inquire({
5757
name: 'selectedTokens',
5858
message: 'CLI_AUTH_TOKENS_REMOVE_SELECT_TOKEN',
@@ -62,15 +62,15 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
6262
log.debug(`User selected ${selectedTokens.length} tokens for removal`, {...this.contextDetails, selectedTokens });
6363

6464
if (selectedTokens.length === 0) {
65-
log.debug('No tokens selected for removal, exiting', this.contextDetails);
65+
log.debug('No tokens selected for removal.', this.contextDetails);
6666
return;
6767
}
6868

6969
selectedTokens.forEach((ele)=>{
7070
log.info(`Selected token: ${ele}`, this.contextDetails);
7171
})
7272

73-
log.debug('Removing selected tokens from configuration', this.contextDetails);
73+
log.debug('Removing selected tokens from configuration.', this.contextDetails);
7474
selectedTokens.forEach((element) => {
7575
const selectedToken = element.split(':')[0];
7676
log.debug(`Removing token: ${selectedToken}`, this.contextDetails);
@@ -79,9 +79,9 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
7979
log.info(`Token removed: ${selectedToken}`, this.contextDetails);
8080
});
8181

82-
log.debug('Token removal process completed successfully', this.contextDetails);
82+
log.debug('Token removal completed successfully.', this.contextDetails);
8383
} catch (error) {
84-
log.debug('Token removal process failed', {...this.contextDetails, error });
84+
log.debug('Token removal failed.', {...this.contextDetails, error });
8585
cliux.print('CLI_AUTH_TOKENS_REMOVE_FAILED', { color: 'yellow' });
8686
handleAndLogError(error, {...this.contextDetails} )
8787
}

0 commit comments

Comments
 (0)