we-promise/sure · error · Thor::Error

At least one credential field is required. Example: api_key:

Error message

At least one credential field is required. Example: api_key:text:secret

What it means

Raised as Thor::Error by the provider global generator (lib/generators/provider/global/global_generator.rb:42) when the fields argument is empty. A global provider item is essentially a credentials container, so at least one credential field (syntax field:type[:secret][:default=value], e.g. api_key:text:secret) is mandatory; with zero fields the generated item model would have nowhere to store credentials and the migration would be meaningless.

Source

Thrown at lib/generators/provider/global/global_generator.rb:42

#
# Key difference from provider:family:
#   - Credentials stored in `settings` table (global, shared by all families)
#   - Item/account tables store connections per family (but not credentials)
#   - No controller/view/routes needed (configuration via /settings/providers)
class Provider::GlobalGenerator < Rails::Generators::NamedBase
  include Rails::Generators::Migration

  source_root File.expand_path("templates", __dir__)

  argument :fields, type: :array, default: [], banner: "field:type[:secret][:default=value] field:type[:secret]"

  class_option :skip_migration, type: :boolean, default: false, desc: "Skip generating migration"
  class_option :skip_models, type: :boolean, default: false, desc: "Skip generating models"
  class_option :skip_adapter, type: :boolean, default: false, desc: "Skip generating adapter"

  def validate_fields
    if parsed_fields.empty?
      raise Thor::Error, "At least one credential field is required. Example: api_key:text:secret"
    end

    # Validate field types
    parsed_fields.each do |field|
      unless %w[text string integer boolean].include?(field[:type])
        raise Thor::Error, "Invalid field type '#{field[:type]}' for #{field[:name]}. Must be one of: text, string, integer, boolean"
      end
    end
  end

  def generate_migration
    return if options[:skip_migration]

    migration_template "global_migration.rb.tt",
                       "db/migrate/create_#{table_name}_and_accounts.rb",
                       migration_version: migration_version
  end

View on GitHub (pinned to e69894adb9)

Solutions

  1. Pass at least one credential field: rails g provider:global acme api_key:text:secret.
  2. Mark secret fields with :secret so the generator wires encrypted/credential handling appropriately.
  3. Check rails g provider:global --help for the field:type[:secret][:default=value] syntax.

Example fix

// before
rails g provider:global acme

// after
rails g provider:global acme api_key:text:secret
Defensive patterns

Strategy: validation

Validate before calling

abort 'need >= 1 credential field (e.g. api_key:text:secret)' if requested_fields.empty?

Try / catch

begin
  Rails::Generators.invoke 'provider:global', ['acme', *fields]
rescue Thor::Error => e
  # message includes a working example; add api_key:text:secret and retry
end

Prevention

When it happens

Trigger: Running rails g provider:global acme with no positional field arguments, or with fields consumed by an earlier typo'd option so parsed_fields ends up empty.

Common situations: First-time use of the generator assuming credentials are configured elsewhere; forgetting that unlike family providers there is no sensible credential-less global provider.

Related errors


AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21). Data as JSON: /api/errors/deb554a5208999c1. Report an issue: GitHub.