{"record":{"id":"b736dce58911a4bd","repo":"hashie/hashie","slug":"tried-to-chain-into-a-non-hash-key","errorCode":null,"errorMessage":"Tried to chain into a non-hash key.","messagePattern":"Tried to chain into a non-hash key\\.","errorType":"exception","errorClass":"Hashie::Clash::ChainError","httpStatus":null,"severity":"error","filePath":"lib/hashie/clash.rb","lineNumber":78,"sourceCode":"      end\n\n      self[key.to_sym] = val\n      self\n    end\n\n    def method_missing(name, *args) #:nodoc:\n      if args.empty? && name.to_s.end_with?('!')\n        key = name[0...-1].to_sym\n\n        case self[key]\n        when NilClass\n          self[key] = self.class.new({}, self)\n        when Clash\n          self[key]\n        when Hash\n          self[key] = self.class.new(self[key], self)\n        else\n          raise ChainError, 'Tried to chain into a non-hash key.'\n        end\n      elsif args.any?\n        merge_store(name, *args)\n      else\n        super\n      end\n    end\n\n    def respond_to_missing?(method_name, _include_private = false)\n      method_name = method_name.to_s\n\n      if method_name.end_with?('!')\n        key = method_name[0...-1].to_sym\n        [NilClass, Clash, Hash].include?(self[key].class)\n      else\n        true\n      end\n    end","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/hashie/hashie/blob/fde8e03a0a19da626576415223e4b002fc373967/lib/hashie/clash.rb#L60-L96","documentation":"Error \"Tried to chain into a non-hash key.\" thrown in hashie/hashie.","triggerScenarios":"Calling a bang method (e.g. clash.foo!) to chain into a key whose current value is a scalar (String, Integer, Array, etc.) instead of nil, a Hash, or a Clash.","commonSituations":"Building a nested options hash with Hashie::Clash and chaining into a key that was already assigned a non-hash value earlier in the chain.","solutions":["Only chain with bang notation (key!) into keys whose current value is nil, a Hash, or a Clash; check the existing value before diving into a sub-hash.","Assign a plain value with non-bang chaining (c.foo(1)) instead of c.foo! when the key should hold a scalar.","If the key already holds a scalar you need to nest under, overwrite it first or restructure the chain so the sub-hash is built before the scalar is set."],"exampleFix":"c = Hashie::Clash.new; c.order(:created_at); c.conditions!.foo('bar')._end! # only chain with bang methods into keys that are unset or hold hashes; overwrite the scalar first or use a different key.","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fde8e03a0a19da626576415223e4b002fc373967","analyzedAt":"2026-08-23T14:54:52.149Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}