we-promise/sure · error · Provider::Trading212::ConfigurationError
Trading 212 API key is missing.
Error message
Trading 212 API key is missing.
What it means
Raised as Provider::Trading212::ConfigurationError by Trading212Item::Syncer#perform_sync (app/models/trading212_item/syncer.rb:14) when trading212_item.credentials_configured? is false (blank api_key or api_secret). The syncer first flips the item's status enum to requires_update, then raises, so the item is visibly flagged in the UI. This is the sync-pipeline counterpart of the 'provider is not configured' error raised deeper in import_latest_data.
Source
Thrown at app/models/trading212_item/syncer.rb:14
class Trading212Item::Syncer
include SyncStats::Collector
attr_reader :trading212_item
def initialize(trading212_item)
@trading212_item = trading212_item
end
def perform_sync(sync)
sync.update!(status_text: I18n.t("trading212_items.sync.status.checking_credentials")) if sync.respond_to?(:status_text)
unless trading212_item.credentials_configured?
trading212_item.update!(status: :requires_update)
raise Provider::Trading212::ConfigurationError, "Trading 212 API key is missing."
end
sync.update!(status_text: I18n.t("trading212_items.sync.status.importing_account")) if sync.respond_to?(:status_text)
trading212_item.import_latest_data
sync.update!(status_text: I18n.t("trading212_items.sync.status.checking_configuration")) if sync.respond_to?(:status_text)
collect_setup_stats(sync, provider_accounts: trading212_item.trading212_accounts.to_a)
unlinked_accounts = trading212_item.trading212_accounts.left_joins(:account_provider).where(account_providers: { id: nil })
linked_accounts = trading212_item.trading212_accounts.joins(:account).merge(Account.visible)
if unlinked_accounts.any?
trading212_item.update!(pending_account_setup: true)
sync.update!(status_text: I18n.t("trading212_items.sync.status.accounts_need_setup", count: unlinked_accounts.count)) if sync.respond_to?(:status_text)
else
trading212_item.update!(pending_account_setup: false)
end
View on GitHub (pinned to e69894adb9)
Solutions
- Update the item's credentials (api_key + api_secret) so credentials_configured? is true, then re-run the sync.
- In calling code, rescue Provider::Trading212::ConfigurationError specifically and surface an 'update your credentials' action instead of a generic failure — the item is already marked requires_update.
- Exclude items without credentials from sync scheduling using the syncable scope (active.where.not(api_key: [nil, ''])).
- For specs, stub credentials_configured? or provide both attributes before invoking perform_sync.
Example fix
// before Trading212Item::Syncer.new(item).perform_sync(sync) # ConfigurationError // after begin Trading212Item::Syncer.new(item).perform_sync(sync) rescue Provider::Trading212::ConfigurationError # item already flagged requires_update; prompt user to re-enter credentials end
Defensive patterns
Strategy: try-catch
Validate before calling
Trading212Item::Syncer.new(item).perform_sync(sync) if item.credentials_configured?
Type guard
item.credentials_configured? && !item.scheduled_for_deletion?
Try / catch
begin Trading212Item::Syncer.new(item).perform_sync(sync) rescue Provider::Trading212::ConfigurationError # item already marked requires_update; notify user to re-enter API credentials rescue => e # unexpected failure: log + report end
Prevention
- Rescue ConfigurationError separately from generic sync errors — it is a user-actionable state.
- Only enqueue syncs for items matching the syncable scope.
- In tests, always provide api_key/api_secret or stub credentials_configured? before perform_sync.
When it happens
Trigger: A scheduled or manual sync (Syncable#perform_sync) running against a Trading212Item with a blank api_key or api_secret; items whose credentials were cleared or never persisted; running the syncer from console on a half-configured test record.
Common situations: User deletes/rotates their Trading 212 key without updating the item; encryption-key mismatch making api_key read as nil; CI running syncer specs on fixtures that lack the encrypted credential attributes.
Related errors
- Trading 212 provider is not configured
- Sophtron provider is not configured
- record_not_found
- Anthropic Model is required when a custom Base URL is set.
- No LLM provider configured that supports model '#{requested_
AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21).
Data as JSON: /api/errors/60f0af5c6b027443.
Report an issue: GitHub.