1 | const { EOL } = require('os');
|
2 |
|
3 | class ReleaseItError extends Error {
|
4 | constructor(...args) {
|
5 | super(...args);
|
6 | Error.captureStackTrace(this, this.constructor);
|
7 | }
|
8 | }
|
9 |
|
10 | class TimeoutError extends ReleaseItError {}
|
11 |
|
12 | class GitCommitError extends ReleaseItError {}
|
13 |
|
14 | class GitHubClientError extends ReleaseItError {}
|
15 |
|
16 | class InvalidVersionError extends ReleaseItError {
|
17 | constructor() {
|
18 | super('An invalid version was provided.');
|
19 | }
|
20 | }
|
21 |
|
22 | class InvalidConfigurationError extends ReleaseItError {
|
23 | constructor(filePath) {
|
24 | super(`Invalid configuration file at ${filePath}`);
|
25 | }
|
26 | }
|
27 |
|
28 | class GitRemoteUrlError extends ReleaseItError {
|
29 | constructor() {
|
30 | super('Could not get remote Git url.' + EOL + 'Please add a remote repository.');
|
31 | }
|
32 | }
|
33 |
|
34 | class GitCleanWorkingDirError extends ReleaseItError {
|
35 | constructor() {
|
36 | super(
|
37 | 'Working dir must be clean.' +
|
38 | EOL +
|
39 | 'Please stage and commit your changes.' +
|
40 | EOL +
|
41 | 'Alternatively, use `--no-git.requireCleanWorkingDir` to include the changes in the release commit' +
|
42 | ' (or save `"git.requireCleanWorkingDir": false` in the configuration).'
|
43 | );
|
44 | }
|
45 | }
|
46 |
|
47 | class GitUpstreamError extends ReleaseItError {
|
48 | constructor() {
|
49 | super(
|
50 | 'No upstream configured for current branch.' +
|
51 | EOL +
|
52 | 'Please set an upstream branch.' +
|
53 | EOL +
|
54 | 'Alternatively, use `--no-git.requireUpstream` to have this set this by release-it' +
|
55 | ' (or save `"git.requireUpstream": false` in the configuration).'
|
56 | );
|
57 | }
|
58 | }
|
59 |
|
60 | class GitNoCommitsError extends ReleaseItError {
|
61 | constructor() {
|
62 | super('There are no commits since the latest tag.');
|
63 | }
|
64 | }
|
65 |
|
66 | class GitNetworkError extends ReleaseItError {
|
67 | constructor(err, remoteUrl) {
|
68 | super(`Unable to fetch from ${remoteUrl}${EOL}${err.message}`);
|
69 | }
|
70 | }
|
71 |
|
72 | class TokenError extends ReleaseItError {
|
73 | constructor(type, tokenRef) {
|
74 | super(
|
75 | `Environment variable "${tokenRef}" is required for ${type} releases.` +
|
76 | EOL +
|
77 | `Documentation: https://github.com/release-it/release-it#${type.toLowerCase()}-releases`
|
78 | );
|
79 | }
|
80 | }
|
81 |
|
82 | class npmTimeoutError extends ReleaseItError {
|
83 | constructor(timeout) {
|
84 | super(`Unable to reach npm registry (timed out after ${timeout}ms).`);
|
85 | }
|
86 | }
|
87 |
|
88 | class npmAuthError extends ReleaseItError {
|
89 | constructor() {
|
90 | super('Not authenticated with npm. Please `npm login` and try again.');
|
91 | }
|
92 | }
|
93 |
|
94 | module.exports = {
|
95 | ReleaseItError,
|
96 | TimeoutError,
|
97 | GitHubClientError,
|
98 | InvalidVersionError,
|
99 | InvalidConfigurationError,
|
100 | GitRemoteUrlError,
|
101 | GitCleanWorkingDirError,
|
102 | GitUpstreamError,
|
103 | GitNoCommitsError,
|
104 | GitCommitError,
|
105 | GitNetworkError,
|
106 | TokenError,
|
107 | npmTimeoutError,
|
108 | npmAuthError
|
109 | };
|