Skip to content

Commit 8314a73

Browse files
authored
Merge pull request #17 from etscrivner/use-standard-error-rather-than-exception
[Fix] Descend From StandardError Not Exception
2 parents 1ef34a9 + 70ac456 commit 8314a73

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

lib/money-tree/key.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ class Key
77
include OpenSSL
88
include Support
99
extend Support
10-
class KeyInvalid < Exception; end
11-
class KeyGenerationFailure < Exception; end
12-
class KeyImportFailure < Exception; end
13-
class KeyFormatNotFound < Exception; end
14-
class InvalidWIFFormat < Exception; end
15-
class InvalidBase64Format < Exception; end
10+
class KeyInvalid < StandardError; end
11+
class KeyGenerationFailure < StandardError; end
12+
class KeyImportFailure < StandardError; end
13+
class KeyFormatNotFound < StandardError; end
14+
class InvalidWIFFormat < StandardError; end
15+
class InvalidBase64Format < StandardError; end
1616

1717
attr_reader :options, :key, :raw_key
1818
attr_accessor :ec_key

lib/money-tree/node.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ class Node
55
attr_reader :private_key, :public_key, :chain_code,
66
:is_private, :depth, :index, :parent
77

8-
class PublicDerivationFailure < Exception; end
9-
class InvalidKeyForIndex < Exception; end
10-
class ImportError < Exception; end
11-
class PrivatePublicMismatch < Exception; end
8+
class PublicDerivationFailure < StandardError; end
9+
class InvalidKeyForIndex < StandardError; end
10+
class ImportError < StandardError; end
11+
class PrivatePublicMismatch < StandardError; end
1212

1313
def initialize(opts = {})
1414
opts.each { |k, v| instance_variable_set "@#{k}", v }

spec/lib/money-tree/private_key_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@
9393
describe "parse_raw_key" do
9494
it "returns error if key is not Bignum, hex, base64, or wif formatted" do
9595
expect { @key = MoneyTree::PrivateKey.new(key: "Thisisnotakey") }.to raise_error(MoneyTree::Key::KeyFormatNotFound)
96-
96+
end
97+
98+
it "raises an error that can be caught using a standard exception block" do
99+
exception_raised = false
100+
101+
begin
102+
MoneyTree::PrivateKey.new(key: "Thisisnotakey")
103+
rescue => ex
104+
exception_raised = true
105+
end
106+
fail unless exception_raised
97107
end
98108
end
99109

0 commit comments

Comments
 (0)