yegor256/sibit

Sibit::Blockchain#price raises NameError instead of Sibit::Error on unknown currency

Open

#264 opened on Jun 20, 2026

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Ruby (6 forks)github user discovery
bughelp wanted

Repository metrics

Stars
 (27 stars)
PR merge metrics
 (PR metrics pending)

Description

Sibit::Blockchain#price at lib/sibit/blockchain.rb:35 raises NameError instead of Sibit::Error whenever blockchain.info has no entry for the requested currency. The line reads raise(Error, "Unrecognized currency #{currency}") if h.nil?, and the bare Error does not resolve to Sibit::Error.

class Sibit::Blockchain uses the qualified-name shortcut, which puts only Sibit::Blockchain in the lexical nesting; Sibit is not implicitly opened. Constant lookup therefore searches Sibit::Blockchain, then its ancestors, then the top level, none of which define Error. A one-liner confirms it under Ruby 3.3:

class Sibit
  class Error < StandardError; end
end
class Sibit::Blockchain
  def fail_it; raise(Error, "hi"); end
end
Sibit::Blockchain.new.fail_it
# => NameError: uninitialized constant Sibit::Blockchain::Error

The other adapters declared with the same shortcut (Sibit::Blockchair, Sibit::Btc, Sibit::Cex, Sibit::Cryptoapis, Sibit::Sochain) all spell out Sibit::Error and Sibit::NotSupportedError, so they are unaffected. lib/sibit.rb and lib/sibit/key.rb use the class Sibit; class Foo form, which does include Sibit in the nesting, so their bare Error references resolve correctly.

The consequence is that Sibit::FirstOf and Sibit::BestOf, which only rescue Sibit::Error, let the NameError propagate and abort the whole chain on what should have been a recoverable per-adapter failure.

Fix is one character: change Error to Sibit::Error on line 35, matching the rest of the file's siblings.

Contributor guide