generated from JS-DevTools/template-node-typescript
-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy patherrors.ts
139 lines (122 loc) · 3.58 KB
/
errors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import os from "node:os";
import {
ACCESS_PUBLIC,
ACCESS_RESTRICTED,
STRATEGY_ALL,
STRATEGY_UPGRADE,
} from "./options.js";
export class InvalidPackageError extends TypeError {
public constructor(value: unknown) {
super(
`Package must be a directory, package.json, or .tgz file, got "${String(
value
)}"`
);
this.name = "PackageJsonReadError";
}
}
export class PackageJsonReadError extends Error {
public constructor(manifestPath: string, originalError: unknown) {
const message = [
`Could not read package.json at ${manifestPath}`,
originalError instanceof Error ? originalError.message : "",
]
.filter(Boolean)
.join(os.EOL);
super(message);
this.name = "PackageJsonReadError";
}
}
export class PackageTarballReadError extends Error {
public constructor(tarballPath: string, originalError: unknown) {
const message = [
`Could not read package.json from ${tarballPath}`,
originalError instanceof Error ? originalError.message : "",
]
.filter(Boolean)
.join(os.EOL);
super(message);
this.name = "PackageTarballReadError";
}
}
export class PackageJsonParseError extends SyntaxError {
public constructor(packageSpec: string, originalError: unknown) {
const message = [
`Invalid JSON, could not parse package.json for ${packageSpec}`,
originalError instanceof Error ? originalError.message : "",
]
.filter(Boolean)
.join(os.EOL);
super(message);
this.name = "PackageJsonParseError";
}
}
export class InvalidPackageNameError extends TypeError {
public constructor(value: unknown) {
super(`Package name is not valid, got "${String(value)}"`);
this.name = "InvalidPackageNameError";
}
}
export class InvalidPackageVersionError extends TypeError {
public constructor(value: unknown) {
super(
`Package version must be a valid semantic version, got "${String(value)}"`
);
this.name = "InvalidPackageVersionError";
}
}
export class InvalidPackagePublishConfigError extends TypeError {
public constructor(value: unknown) {
super(`Publish config must be an object, got "${String(value)}"`);
this.name = "InvalidPackagePublishConfigError";
}
}
export class InvalidRegistryUrlError extends TypeError {
public constructor(value: unknown) {
super(`Registry URL invalid, got "${String(value)}"`);
this.name = "InvalidRegistryUrlError";
}
}
export class InvalidTokenError extends TypeError {
public constructor() {
super("Token must be a non-empty string.");
this.name = "InvalidTokenError";
}
}
export class InvalidTagError extends TypeError {
public constructor(value: unknown) {
super(`Tag must be a non-empty string, got "${String(value)}".`);
this.name = "InvalidTagError";
}
}
export class InvalidAccessError extends TypeError {
public constructor(value: unknown) {
super(
`Access must be "${ACCESS_PUBLIC}" or "${ACCESS_RESTRICTED}", got "${String(
value
)}".`
);
this.name = "InvalidAccessError";
}
}
export class InvalidStrategyError extends TypeError {
public constructor(value: unknown) {
super(
`Strategy must be "${STRATEGY_UPGRADE}" or "${STRATEGY_ALL}", got "${String(
value
)}".`
);
this.name = "InvalidStrategyError";
}
}
export class NpmCallError extends Error {
public constructor(command: string, exitCode: number, stderr: string) {
super(
[
`Call to "npm ${command}" exited with non-zero exit code ${exitCode}`,
stderr,
].join(os.EOL)
);
this.name = "NpmCallError";
}
}