{"record":{"id":"37e9fe3f531aed15","repo":"we-promise/sure","slug":"binance-credentials-not-configured","errorCode":null,"errorMessage":"Binance credentials not configured","messagePattern":"Binance credentials not configured","errorType":"exception","errorClass":"StandardError","httpStatus":null,"severity":"error","filePath":"app/models/binance_item.rb","lineNumber":38,"sourceCode":"  has_one_attached :logo, dependent: :purge_later\n\n  has_many :binance_accounts, dependent: :destroy\n  has_many :accounts, through: :binance_accounts\n\n  scope :active, -> { where(scheduled_for_deletion: false) }\n  scope :syncable, -> { active }\n  scope :ordered, -> { order(created_at: :desc) }\n  scope :needs_update, -> { where(status: :requires_update) }\n\n  def destroy_later\n    update!(scheduled_for_deletion: true)\n    DestroyJob.perform_later(self)\n  end\n\n  def import_latest_binance_data\n    provider = binance_provider\n    unless provider\n      raise StandardError, \"Binance credentials not configured\"\n    end\n\n    BinanceItem::Importer.new(self, binance_provider: provider).import\n  rescue StandardError => e\n    Rails.logger.error \"BinanceItem #{id} - Failed to import: #{e.message}\"\n    raise\n  end\n\n  def process_accounts\n    Rails.logger.info \"BinanceItem #{id} - process_accounts: total binance_accounts=#{binance_accounts.count}\"\n\n    return [] if binance_accounts.empty?\n\n    binance_accounts.each do |ba|\n      Rails.logger.info(\n        \"BinanceItem #{id} - binance_account #{ba.id}: \" \\\n        \"name='#{ba.name}' \" \\\n        \"account_provider=#{ba.account_provider&.id || 'nil'} \" \\","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/binance_item.rb#L20-L56","documentation":"Raised by BinanceItem#import_latest_binance_data when binance_provider (from the Provided concern) returns nil, i.e. the item has no usable API credentials — credentials_configured? (api_key present AND api_secret present) is false. It is a plain StandardError, logged as \"BinanceItem <id> - Failed to import: Binance credentials not configured\" and re-raised, so a sync job that hits it fails visibly.","triggerScenarios":"A sync/import job (or console call) runs import_latest_binance_data on a BinanceItem row whose api_key or api_secret is blank: created outside the normal form flow (seed, console, data import bypassing presence validations), or credentials wiped by an update — then provider construction returns nil and the guard at app/models/binance_item.rb:37-39 fires.","commonSituations":"Seeded/demo rows without real keys; ActiveRecord encryption misconfiguration (encrypts :api_key/:api_secret active in one env but the ciphertext unreadable/blank in another, e.g. missing encryption key in a migrated environment); partial record copies between databases.","solutions":["Set real credentials on the item: binance_item.update!(api_key: ..., api_secret: ...) — presence validations on both columns exist for exactly this reason.","Guard scheduled syncs with credentials_configured? and skip (or mark status: requires_update) instead of letting the job raise.","If credentials exist but read blank, check AR encryption setup: encryption_ready? gated encrypts on the columns, so a missing/changed encryption key in this environment can surface as unreadable values.","Audit rows: BinanceItem.where(api_key: [nil, '']).or(BinanceItem.where(api_secret: [nil, ''])) to find broken items."],"exampleFix":"# before\nbinance_item.import_latest_binance_data\n\n# after\nunless binance_item.credentials_configured?\n  Rails.logger.warn \"BinanceItem #{binance_item.id} skipped: credentials missing\"\n  next\nend\nbinance_item.import_latest_binance_data","handlingStrategy":"validation","validationCode":"raise ArgumentError, \"Binance credentials missing\" unless binance_item.credentials_configured?\n# equivalent pre-check: binance_item.api_key.present? && binance_item.api_secret.present?","typeGuard":"# Ruby\ndef importable_binance_item?(item)\n  item.is_a?(BinanceItem) && item.active? && item.credentials_configured? # active excludes scheduled_for_deletion\nend","tryCatchPattern":"begin\n  binance_item.import_latest_binance_data\nrescue StandardError => e\n  raise unless e.message.include?(\"credentials not configured\")\n  Rails.logger.warn(\"BinanceItem #{binance_item.id} skipped sync: credentials missing\")\nend","preventionTips":["Gate every scheduled sync on credentials_configured? and skip/mark requires_update instead of raising inside the job.","Only create BinanceItem rows through flows that enforce the api_key/api_secret presence validations (no console/seed shortcuts).","Verify AR encryption keys are configured in every environment — the encrypts columns can surface as unreadable values when keys are missing."],"tags":["binance","credentials","configuration","sync","provider"],"backgroundTag":"missing-credentials","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}