Exception: Hive::BaseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/hive/base_error.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error = nil, cause = nil) ⇒ BaseError

Returns a new instance of BaseError.



3
4
5
6
# File 'lib/hive/base_error.rb', line 3

def initialize(error = nil, cause = nil)
  @error = error
  @cause = cause
end

Class Method Details

.build_error(error, context) ⇒ Object

Raises:



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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/hive/base_error.rb', line 16

def self.build_error(error, context)
  if error.message == 'Unable to acquire database lock'
    raise Hive::RemoteDatabaseLockError, error.message, build_backtrace(error)
  end
  
  if error.message.include? 'Internal Error'
    raise Hive::RemoteInternalError, error.message, build_backtrace(error)
  end
  
  if error.message.include? 'Server error'
    raise Hive::RemoteServerError, error.message, build_backtrace(error)
  end
  
  if error.message.include?('plugin not enabled') || error.message.include?('Could not find API')
    raise Hive::PluginNotEnabledError, error.message, build_backtrace(error)
  end
  
  if error.message.include? 'Supported by hivemind'
    raise Hive::MethodNotEnabledError, error.message, build_backtrace(error)
  end
  
  if error.message.include? 'argument'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Invalid params'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.start_with? 'Bad Cast:'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'prefix_len'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Parse Error'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'unknown key'
    raise Hive::ArgumentError, "#{context}: #{error.message} (or content has been deleted)", build_backtrace(error)
  end
  
  if error.message.include? 'Comment is not in account\'s comments'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Could not find comment'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'unable to convert ISO-formatted string to fc::time_point_sec'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Input data have to treated as object.'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'base.amount > share_type(0)'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Invalid parameter'
    raise Hive::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'blk->transactions.size() > itr->trx_in_block'
    raise Hive::VirtualOperationsNotAllowedError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'A transaction must have at least one operation'
    raise Hive::EmptyTransactionError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'transaction expiration exception'
    raise Hive::TransactionExpiredError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Duplicate transaction check failed'
    raise Hive::DuplicateTransactionError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'signature is not canonical'
    raise Hive::NonCanonicalSignatureError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'attempting to push a block that is too old'
    raise Hive::BlockTooOldError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'irrelevant signature'
    raise Hive::IrrelevantSignatureError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'missing required posting authority'
    raise Hive::MissingPostingAuthorityError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'missing required active authority'
    raise Hive::MissingActiveAuthorityError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'missing required owner authority'
    raise Hive::MissingOwnerAuthorityError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'missing required other authority'
    raise Hive::MissingOtherAuthorityError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Upstream response error'
    raise Hive::UpstreamResponseError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Request Timeout'
    raise Hive::RequestTimeoutUpstreamResponseError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Bad or missing upstream response'
    raise Hive::BadOrMissingUpstreamResponseError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'operator has disabled operation indexing by transaction_id'
    raise Hive::TransactionIndexDisabledError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include?('Assert Exception:false: Account name ') && error.message.include?(' is not valid. Please follow the RFC 1035 rules.')
    raise Hive::InvalidAccountError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include?('Method') && error.message.include?(' does not exist.')
    raise Hive::UnknownMethodError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Invalid operation name'
    raise Hive::UnknownOperationError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message =~ /Invalid object name: .+_operation/
    raise Hive::UnknownOperationError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Author not found'
    raise Hive::AuthorNotFoundError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? ' != fc::time_point_sec::maximum()'
    raise Hive::ReachedMaximumTimeError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Cannot transfer a negative amount (aka: stealing)'
    raise Hive::TheftError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'Must transfer a nonzero amount'
    raise Hive::NonZeroRequiredError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  if error.message.include? 'is_asset_type'
    raise Hive::UnexpectedAssetError, "#{context}: #{error.message}", build_backtrace(error)
  end
  
  puts JSON.pretty_generate(error) if ENV['DEBUG']
  raise UnknownError, "#{context}: #{error.message}", build_backtrace(error)
end

Instance Method Details

#to_sObject



8
9
10
11
12
13
14
# File 'lib/hive/base_error.rb', line 8

def to_s
  detail = {}
  detail[:error] = @error if !!@error
  detail[:cause] = @cause if !!@cause
  
  JSON[detail] rescue detail.to_s
end