{"record":{"id":"c92dee90589d0b3a","repo":"instructure/canvas-lms","slug":"unsupported-type-cast-type-cast-for-setting-setting-name-c92dee","errorCode":null,"errorMessage":"Unsupported type_cast `#{type_cast}` for setting `#{setting_name}`","messagePattern":"Unsupported type_cast `#(.+?)` for setting `#(.+?)`","errorType":"validation","errorClass":"Errors::InvalidTypeCast","httpStatus":null,"severity":"error","filePath":"lib/canvas_operations/base_concerns/settings.rb","lineNumber":137,"sourceCode":"          self.class.send(setting_name, cluster:)\n        end\n        protected setting_name\n      end\n\n      def validate_type_cast!(type_cast, setting_name)\n        case type_cast\n        when Symbol\n          # Setting values are always Strings, so ensure the type_cast method exists on String\n          unless SETTINGS_TYPE_INSTANCE.respond_to?(type_cast)\n            raise Errors::InvalidTypeCast,\n                  \"Unsupported type_cast `#{type_cast}` for setting `#{setting_name}`. #{SETTINGS_TYPE_INSTANCE.class} does not respond to `#{type_cast}`.\"\n          end\n        when Proc\n          unless type_cast.arity == 1\n            raise Errors::InvalidTypeCast, \"type_cast Proc must take exactly one argument for setting `#{setting_name}`\"\n          end\n        else\n          raise Errors::InvalidTypeCast, \"Unsupported type_cast `#{type_cast}` for setting `#{setting_name}`\"\n        end\n      end\n\n      def settings_key(setting_name, cluster:)\n        \"clusters/#{cluster}/#{operation_name}/#{setting_name}\"\n      end\n    end\n  end\nend\n","sourceCodeStart":119,"sourceCodeEnd":147,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/canvas_operations/base_concerns/settings.rb#L119-L147","documentation":"CanvasOperations::Errors::InvalidTypeCast raised by the else branch of validate_type_cast!: the type_cast argument is neither a Symbol nor a Proc. Only those two forms are supported for converting the raw String Setting value.","triggerScenarios":"Passing type_cast: 'to_i' (a String), type_cast: Integer, a class, or an array as the type_cast option to setting.","commonSituations":"Quoting the symbol by accident; passing a class like Float instead of the symbol :to_f; dynamically computed cast values that end up nil or a string.","solutions":["Use a Symbol (e.g. :to_i) or a one-argument Proc for type_cast","Convert a String cast name to a symbol: type_cast.to_sym (after verifying it's a valid String method)","Remove the type_cast option to accept the default :to_s behavior"],"exampleFix":"// before\nsetting(:limit, default: 10, type_cast: 'to_i')\n// after\nsetting(:limit, default: 10, type_cast: :to_i)","handlingStrategy":"type-guard","validationCode":"raise 'type_cast must be Symbol or Proc' unless type_cast.is_a?(Symbol) || type_cast.is_a?(Proc)","typeGuard":"def valid_type_cast?(tc)\n  tc.is_a?(Symbol) || tc.is_a?(Proc)\nend","tryCatchPattern":"rescue CanvasOperations::Errors::InvalidTypeCast\n  value = default.to_s\nend","preventionTips":["Never quote cast symbols","Don't pass classes like Integer as casts","Validate config-provided cast names before use"],"tags":["ruby","type-cast","arguments","canvas-operations"],"backgroundTag":"invalid-argument-value","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}