Skip to content

Commit d096210

Browse files
chore: move error messages into message files
1 parent f703008 commit d096210

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

messages/scratchOrgCreate.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,23 @@ Org snapshots don’t support one or more options you specified: %s.
55
# SourceStatusResetFailureError
66

77
Successfully created org with ID: %s and name: %s. Unfortunately, source tracking isn’t working as expected. If you run force:source:status, the results may be incorrect. Try again by creating another scratch org.
8+
9+
# DurationDaysValidationMinError
10+
11+
Expected 'durationDays' greater than or equal to %s but received %s.
12+
13+
# DurationDaysValidationMaxError
14+
15+
Expected 'durationDays' less than or equal to %s but received %s.
16+
17+
# DurationDaysNotIntError
18+
19+
Expected 'durationDays' to be an integer number.
20+
21+
# RetryNotIntError
22+
23+
Expected 'retry' to be an integer number.
24+
25+
# WaitValidationMaxError
26+
27+
Expected 'wait' greater than or equal to %s but received %s.

src/org/scratchOrgCreate.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
8-
// third
97
import { Duration } from '@salesforce/kit';
108
import { ensureString, getString } from '@salesforce/ts-types';
11-
12-
// Local
139
import { Messages } from '../messages';
1410
import { Logger } from '../logger';
1511
import { ConfigAggregator } from '../config/configAggregator';
@@ -29,7 +25,14 @@ import { AuthFields, AuthInfo } from './authInfo';
2925
import { Connection } from './connection';
3026

3127
Messages.importMessagesDirectory(__dirname);
32-
const messages = Messages.load('@salesforce/core', 'scratchOrgCreate', ['SourceStatusResetFailureError']);
28+
const messages = Messages.load('@salesforce/core', 'scratchOrgCreate', [
29+
'SourceStatusResetFailureError',
30+
'DurationDaysValidationMaxError',
31+
'DurationDaysValidationMinError',
32+
'RetryNotIntError',
33+
'WaitValidationMaxError',
34+
'DurationDaysNotIntError',
35+
]);
3336

3437
export const DEFAULT_STREAM_TIMEOUT_MINUTES = 6;
3538

@@ -78,33 +81,26 @@ const validateDuration = (durationDays: number): void => {
7881
const max = 30;
7982
if (Number.isInteger(durationDays)) {
8083
if (durationDays < min) {
81-
throw new SfdxError(
82-
`Expected 'durationDays' greater than or equal to ${min} but received ${durationDays}`,
83-
'BoundsError'
84-
);
84+
throw messages.createError('DurationDaysValidationMinError', [min, durationDays]);
8585
}
8686
if (durationDays > max) {
87-
throw new SfdxError(
88-
`Expected 'durationDays' less than or equal to ${max} but received ${durationDays}`,
89-
'BoundsError'
90-
);
87+
throw messages.createError('DurationDaysValidationMaxError', [max, durationDays]);
9188
}
9289
return;
9390
}
94-
throw new SfdxError("Expected 'durationDays' to be an integer number", 'TypeError');
91+
throw messages.createError('DurationDaysNotIntError');
9592
};
9693

9794
const validateRetry = (retry: number): void => {
98-
if (Number.isInteger(retry)) {
99-
return;
95+
if (!Number.isInteger(retry)) {
96+
throw messages.createError('RetryNotIntError');
10097
}
101-
throw new SfdxError("Expected 'retry' to be an integer number", 'TypeError');
10298
};
10399

104100
const validateWait = (wait: Duration): void => {
105101
const min = 2;
106102
if (wait.minutes < min) {
107-
throw new SfdxError(`Expected 'wait' greater than or equal to ${min} but received ${wait}`, 'BoundsError');
103+
throw messages.createError('WaitValidationMaxError', [min, wait.minutes]);
108104
}
109105
};
110106

src/status/pollingClient.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { retryDecorator, NotRetryableError } from 'ts-retry-promise';
1010
import { Logger } from '../logger';
1111
import { SfdxError } from '../sfdxError';
1212
import { Lifecycle } from '../lifecycleEvents';
13-
import { StatusResult } from './streamingClient';
13+
import { StatusResult } from './types';
1414

1515
/**
1616
* This is a polling client that can be used to poll the status of long running tasks. It can be used as a replacement
@@ -77,8 +77,6 @@ export class PollingClient extends AsyncOptionalCreatable<PollingClient.Options>
7777
throw new NotRetryableError(err.name);
7878
}
7979
if (result.completed) {
80-
// TODO v3.0: payload should be of type T always so that
81-
// consumers get the same type in return.
8280
return result.payload as unknown as T;
8381
}
8482
throw new Error('Operation did not complete. Retrying...'); // triggers a retry

0 commit comments

Comments
 (0)