{"record":{"id":"7db9d8c0625efc54","repo":"mongodb/mongoid","slug":"cannot-translate-value-inspect-value-class","errorCode":null,"errorMessage":"cannot translate #{value.inspect} (#{value.class}) to a direction specification","messagePattern":"cannot translate #(.+?) \\(#(.+?)\\) to a direction specification","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/mongoid/criteria/translator.rb","lineNumber":38,"sourceCode":"      #   Translator.to_direction(\"1\")\n      #   Translator.to_direction(-1)\n      #   Translator.to_direction(score: { \"$meta\": \"textScore\" })\n      #\n      # @param [ Hash | Numeric | String | Symbol ] value The value to convert.\n      #\n      # @return [ Hash | Numeric ] The direction.\n      def to_direction(value)\n        case value\n        when Hash\n          value\n        when Numeric\n          value\n        when String\n          /desc/i.match?(value) ? -1 : 1\n        when Symbol\n          to_direction(value.to_s)\n        else\n          raise ArgumentError, \"cannot translate #{value.inspect} (#{value.class}) to a direction specification\"\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":20,"sourceCodeEnd":44,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/criteria/translator.rb#L20-L44","documentation":"Translator.to_direction converts sort specifications: Hashes, Numerics, and strings/symbols containing 'desc' are accepted. Any other object cannot be interpreted as a sort direction and raises this ArgumentError naming the offending value.","triggerScenarios":"Thrown at lib/mongoid/criteria/translator.rb:38 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass 1/-1, a Hash, or an 'asc'/'desc' string/symbol as the direction","Wrap custom direction objects into one of the accepted forms before ordering"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","contentChangedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}