-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
Copy patherrors.js
137 lines (127 loc) · 5.82 KB
/
errors.js
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
/*
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/>.
*/
/**
* @file errors.js
* @author Fabian Vogelsteller <fabian@ethereum.org>
* @author Marek Kotewicz <marek@parity.io>
* @date 2017
*/
"use strict";
module.exports = {
ErrorResponse: function (result) {
var message = !!result && !!result.error && !!result.error.message ? result.error.message : JSON.stringify(result);
var data = (!!result.error && !!result.error.data) ? result.error.data : null;
var err = new Error('Returned error: ' + message);
err.data = data;
return err;
},
InvalidNumberOfParams: function (got, expected, method) {
return new Error('Invalid number of parameters for "'+ method +'". Got '+ got +' expected '+ expected +'!');
},
InvalidConnection: function (host, event){
return this.ConnectionError('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.', event);
},
InvalidProvider: function () {
return new Error('Provider not set or invalid');
},
InvalidResponse: function (result){
var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result);
return new Error(message);
},
ConnectionTimeout: function (ms){
return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived');
},
ConnectionNotOpenError: function (event){
return this.ConnectionError('connection not open on send()', event);
},
ConnectionCloseError: function (event){
if (typeof event === 'object' && event.code && event.reason) {
return this.ConnectionError(
'CONNECTION ERROR: The connection got closed with ' +
'the close code `' + event.code + '` and the following ' +
'reason string `' + event.reason + '`',
event
);
}
return new Error('CONNECTION ERROR: The connection closed unexpectedly');
},
MaxAttemptsReachedOnReconnectingError: function (){
return new Error('Maximum number of reconnect attempts reached!');
},
PendingRequestsOnReconnectingError: function (){
return new Error('CONNECTION ERROR: Provider started to reconnect before the response got received!');
},
ConnectionError: function (msg, event){
const error = new Error(msg);
if (event) {
error.code = event.code;
error.reason = event.reason;
}
return error;
},
RevertInstructionError: function(reason, signature) {
var error = new Error('Your request got reverted with the following reason string: ' + reason);
error.reason = reason;
error.signature = signature;
return error;
},
TransactionRevertInstructionError: function(reason, signature, receipt) {
var error = new Error('Transaction has been reverted by the EVM:\n' + JSON.stringify(receipt, null, 2));
error.reason = reason;
error.signature = signature;
error.receipt = receipt;
return error;
},
TransactionError: function(message, receipt) {
var error = new Error(message);
error.receipt = receipt;
return error;
},
NoContractAddressFoundError: function(receipt) {
return this.TransactionError('The transaction receipt didn\'t contain a contract address.', receipt);
},
ContractCodeNotStoredError: function(receipt) {
return this.TransactionError('The contract code couldn\'t be stored, please check your gas limit.', receipt);
},
TransactionRevertedWithoutReasonError: function(receipt) {
return this.TransactionError('Transaction has been reverted by the EVM:\n' + JSON.stringify(receipt, null, 2), receipt);
},
TransactionOutOfGasError: function(receipt) {
return this.TransactionError('Transaction ran out of gas. Please provide more gas:\n' + JSON.stringify(receipt, null, 2), receipt);
},
ResolverMethodMissingError: function(address, name) {
return new Error('The resolver at ' + address + 'does not implement requested method: "' + name + '".');
},
ContractMissingABIError: function() {
return new Error('You must provide the json interface of the contract when instantiating a contract object.');
},
ContractOnceRequiresCallbackError: function() {
return new Error('Once requires a callback as the second parameter.');
},
ContractEventDoesNotExistError: function(eventName) {
return new Error('Event "' + eventName + '" doesn\'t exist in this contract.');
},
ContractReservedEventError: function(type) {
return new Error('The event "'+ type +'" is a reserved event name, you can\'t use it.');
},
ContractMissingDeployDataError: function() {
return new Error('No "data" specified in neither the given options, nor the default options.');
},
ContractNoAddressDefinedError: function() {
return new Error('This contract object doesn\'t have address set yet, please set an address first.');
},
ContractNoFromAddressDefinedError: function() {
return new Error('No "from" address specified in neither the given options, nor the default options.');
}
};