we-promise/sure · error · Thor::Error
Invalid field type '#{field[:type]}' for #{field[:name]}. Mu
Error message
Invalid field type '#{field[:type]}' for #{field[:name]}. Must be one of: text, string, integer, boolean What it means
Raised as Thor::Error by the provider global generator (lib/generators/provider/global/global_generator.rb:48) when a credential field's declared type is not one of text, string, integer, boolean. Same restriction as the family generator: the migration template can only emit those four types, so types like datetime, json, or decimal are rejected during validate_fields, before any file is generated.
Source
Thrown at lib/generators/provider/global/global_generator.rb:48
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
def create_models
return if options[:skip_models]
# Create item model
item_model_path = "app/models/#{file_name}_item.rb"
if File.exist?(item_model_path)View on GitHub (pinned to e69894adb9)
Solutions
- Use text for blobs/JSON keys and string for timestamps; parse in the model code.
- Or generate with valid types and hand-edit the migration plus model to refine the column type.
- Validation runs first, so a failed invocation leaves the tree clean — just re-run with corrected args.
Example fix
// before rails g provider:global acme keyfile:json // after rails g provider:global acme keyfile:text:secret
Defensive patterns
Strategy: validation
Validate before calling
ALLOWED = %w[text string integer boolean]
fields.each { |f| name, type = f.split(':'); raise "#{name}: #{type} invalid" unless ALLOWED.include?(type) } Type guard
type = arg.split(':')[1]
%w[text string integer boolean].include?(type) Try / catch
begin Rails::Generators.invoke 'provider:global', args rescue Thor::Error => e # correct the named field's type to text/string/integer/boolean and re-run end
Prevention
- JSON keyfiles and blobs -> text (:secret), timestamps -> string; refine types in the generated migration.
- Validation precedes file generation, so failed runs leave a clean tree.
- Keep a checked-in Rake task wrapping provider generator calls with type validation.
When it happens
Trigger: Running rails g provider:global acme token:json expires:datetime secret:decimal — any :type suffix outside the allowed four.
Common situations: Modeling a provider credential that is naturally structured (JSON keyfile) or time-based (token expiry); forgetting the :secret modifier is separate from the type.
Related errors
- Invalid field type '#{field[:type]}' for #{field[:name]}. Mu
- #{reserved.join(', ')} #{reserved.one? ? 'is' : 'are'} alrea
- At least one credential field is required. Example: api_key:
- record_not_found
- validation_failed
AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21).
Data as JSON: /api/errors/e79563e427ba7a66.
Report an issue: GitHub.