instructure/canvas-lms · error · ArgumentError
setting_name must be a symbol or string
Error message
setting_name must be a symbol or string
What it means
ArgumentError raised by CanvasOperations::Settings#setting when setting_name is neither a Symbol nor a String. This strictness guarantees the settings_key namespace is built from a predictable, inspectable name.
Solutions
- Convert the value: name.to_s or name.to_sym before calling setting
- Verify the variable actually contains the setting's name, not a record or ID
- Use a constant/enum of allowed setting names
Example fix
// before setting(id, default: 5) // after setting(id.to_s, default: 5)
Defensive patterns
Strategy: type-guard
Validate before calling
raise 'must be Symbol or String' unless name.is_a?(Symbol) || name.is_a?(String)
Type guard
def valid_setting_name?(name) name.is_a?(Symbol) || name.is_a?(String) end
Try / catch
rescue ArgumentError => e
Rails.logger.error("Bad setting name: #{e.message}")
end Prevention
- Normalize names with .to_s/.to_sym before calling
- Verify variables hold the name, not a record or ID
- Type-annotate config parsers so names parse as strings
When it happens
Trigger: Passing an Integer, nil-like wrapper, or other object as setting_name, e.g. setting(42, default: ...), or a variable holding a non-string type.
Common situations: Interpolating numbers/IDs directly as setting names; reading the name from JSON where it parsed as a number; passing a configuration object instead of its key.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- progress_tracking must be a boolean
- setting_name cannot be nil
- Unsupported type_cast `#
- all elements must be User objects
- Invalid mode: #
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/65e642945679dc98.
Report an issue: GitHub.
Appendix: source
Thrown at lib/canvas_operations/base_concerns/settings.rb:83
Canvas::Reloader.reload
settings_key = settings_key(name, cluster:)
value = Setting.get(settings_key, default)
log_message("Fetched setting #{settings_key} with value `#{value.inspect}` before type casting", level: :debug)
value
end
def modify_setting_for(name, value, cluster:)
was_success = Setting.set(settings_key(name, cluster:), value)
log_message("Modified setting #{settings_key(name, cluster:)} to value `#{value.inspect}` successfully? #{was_success}")
was_success
end
def setting(setting_name, default:, type_cast: :to_s)
raise ArgumentError, "setting_name cannot be nil" if setting_name.nil?
raise ArgumentError, "setting_name must be a symbol or string" unless setting_name.is_a?(Symbol) || setting_name.is_a?(String)
validate_type_cast!(type_cast, setting_name)
# Method to get the Setting value and apply type casting
#
# If no cluster is provided, the current shard's cluster.
define_singleton_method(setting_name) do |cluster: nil|
cluster ||= Shard.current.database_server.id
raw_value = setting_for(setting_name, default:, cluster:)
case type_cast
when Symbol
raw_value.public_send(type_cast)
when Proc
type_cast.call(raw_value)
end
endView on GitHub (pinned to 1c9f0bb801)