{"record":{"id":"deb554a5208999c1","repo":"we-promise/sure","slug":"at-least-one-credential-field-is-required-example","errorCode":null,"errorMessage":"At least one credential field is required. Example: api_key:text:secret","messagePattern":"At least one credential field is required\\. Example: api_key:text:secret","errorType":"exception","errorClass":"Thor::Error","httpStatus":null,"severity":"error","filePath":"lib/generators/provider/global/global_generator.rb","lineNumber":42,"sourceCode":"#\n# Key difference from provider:family:\n#   - Credentials stored in `settings` table (global, shared by all families)\n#   - Item/account tables store connections per family (but not credentials)\n#   - No controller/view/routes needed (configuration via /settings/providers)\nclass Provider::GlobalGenerator < Rails::Generators::NamedBase\n  include Rails::Generators::Migration\n\n  source_root File.expand_path(\"templates\", __dir__)\n\n  argument :fields, type: :array, default: [], banner: \"field:type[:secret][:default=value] field:type[:secret]\"\n\n  class_option :skip_migration, type: :boolean, default: false, desc: \"Skip generating migration\"\n  class_option :skip_models, type: :boolean, default: false, desc: \"Skip generating models\"\n  class_option :skip_adapter, type: :boolean, default: false, desc: \"Skip generating adapter\"\n\n  def validate_fields\n    if parsed_fields.empty?\n      raise Thor::Error, \"At least one credential field is required. Example: api_key:text:secret\"\n    end\n\n    # Validate field types\n    parsed_fields.each do |field|\n      unless %w[text string integer boolean].include?(field[:type])\n        raise Thor::Error, \"Invalid field type '#{field[:type]}' for #{field[:name]}. Must be one of: text, string, integer, boolean\"\n      end\n    end\n  end\n\n  def generate_migration\n    return if options[:skip_migration]\n\n    migration_template \"global_migration.rb.tt\",\n                       \"db/migrate/create_#{table_name}_and_accounts.rb\",\n                       migration_version: migration_version\n  end\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/lib/generators/provider/global/global_generator.rb#L24-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"First-time use of the generator assuming credentials are configured elsewhere; forgetting that unlike family providers there is no sensible credential-less global provider.","solutions":["Pass at least one credential field: rails g provider:global acme api_key:text:secret.","Mark secret fields with :secret so the generator wires encrypted/credential handling appropriately.","Check rails g provider:global --help for the field:type[:secret][:default=value] syntax."],"exampleFix":"// before\nrails g provider:global acme\n\n// after\nrails g provider:global acme api_key:text:secret","handlingStrategy":"validation","validationCode":"abort 'need >= 1 credential field (e.g. api_key:text:secret)' if requested_fields.empty?","typeGuard":null,"tryCatchPattern":"begin\n  Rails::Generators.invoke 'provider:global', ['acme', *fields]\nrescue Thor::Error => e\n  # message includes a working example; add api_key:text:secret and retry\nend","preventionTips":["A global provider item is a credentials container — always pass at least one field.","Use the documented syntax field:type[:secret][:default=value] and mark secrets with :secret.","Run rails g provider:global --help once to internalize the banner before first use."],"tags":["rails","generator","thor","credentials","cli"],"backgroundTag":"generator-missing-required-argument","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}