yegor256/sibit

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

Closed

#264 建立於 2026年6月20日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)Ruby (6 fork)github user discovery
bughelp wanted

倉庫指標

Star
 (27 star)
PR 合併指標
 (PR 指標待抓取)

描述

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.

貢獻者指南