-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
utils_errors.ts
148 lines (115 loc) · 3.63 KB
/
utils_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
140
141
142
143
144
145
146
147
148
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/* eslint-disable max-classes-per-file */
import {
ERR_INVALID_BYTES,
ERR_INVALID_NUMBER,
ERR_INVALID_ADDRESS,
ERR_INVALID_BLOCK,
ERR_INVALID_BOOLEAN,
ERR_INVALID_HEX,
ERR_INVALID_LARGE_VALUE,
ERR_INVALID_NIBBLE_WIDTH,
ERR_INVALID_SIZE,
ERR_INVALID_STRING,
ERR_INVALID_TYPE,
ERR_INVALID_TYPE_ABI,
ERR_INVALID_UNIT,
ERR_INVALID_UNSIGNED_INTEGER,
} from '../error_codes.js';
import { InvalidValueError } from '../web3_error_base.js';
export class InvalidBytesError extends InvalidValueError {
public code = ERR_INVALID_BYTES;
public constructor(value: unknown) {
super(value, 'can not parse as byte data');
}
}
export class InvalidNumberError extends InvalidValueError {
public code = ERR_INVALID_NUMBER;
public constructor(value: unknown) {
super(value, 'can not parse as number data');
}
}
export class InvalidAddressError extends InvalidValueError {
public code = ERR_INVALID_ADDRESS;
public constructor(value: unknown) {
super(value, 'invalid ethereum address');
}
}
export class InvalidStringError extends InvalidValueError {
public code = ERR_INVALID_STRING;
public constructor(value: unknown) {
super(value, 'not a valid string');
}
}
export class InvalidUnitError extends InvalidValueError {
public code = ERR_INVALID_UNIT;
public constructor(value: unknown) {
super(value, 'invalid unit');
}
}
export class HexProcessingError extends InvalidValueError {
public code = ERR_INVALID_HEX;
public constructor(value: unknown) {
super(value, 'can not be converted to hex');
}
}
export class NibbleWidthError extends InvalidValueError {
public code = ERR_INVALID_NIBBLE_WIDTH;
public constructor(value: string) {
super(value, 'value greater than the nibble width');
}
}
export class InvalidTypeError extends InvalidValueError {
public code = ERR_INVALID_TYPE;
public constructor(value: unknown) {
super(value, 'invalid type, type not supported');
}
}
export class InvalidBooleanError extends InvalidValueError {
public code = ERR_INVALID_BOOLEAN;
public constructor(value: unknown) {
super(value, 'not a valid boolean.');
}
}
export class InvalidUnsignedIntegerError extends InvalidValueError {
public code = ERR_INVALID_UNSIGNED_INTEGER;
public constructor(value: unknown) {
super(value, 'not a valid unsigned integer.');
}
}
export class InvalidSizeError extends InvalidValueError {
public code = ERR_INVALID_SIZE;
public constructor(value: unknown) {
super(value, 'invalid size given.');
}
}
export class InvalidLargeValueError extends InvalidValueError {
public code = ERR_INVALID_LARGE_VALUE;
public constructor(value: unknown) {
super(value, 'value is larger than size.');
}
}
export class InvalidBlockError extends InvalidValueError {
public code = ERR_INVALID_BLOCK;
public constructor(value: string) {
super(value, 'invalid string given');
}
}
export class InvalidTypeAbiInputError extends InvalidValueError {
public code = ERR_INVALID_TYPE_ABI;
public constructor(value: string) {
super(value, 'components found but type is not tuple');
}
}