UNPKG

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