{"record":{"id":"4dc5331867ec3fea","repo":"bkeepers/dotenv","slug":"invalid-value-for-overwrite-overwrite-inspect","errorCode":null,"errorMessage":"Invalid value for overwrite: #{overwrite.inspect}","messagePattern":"Invalid value for overwrite: #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/dotenv.rb","lineNumber":110,"sourceCode":"  end\n\n  # Update `ENV` with the given hash of keys and values\n  #\n  # @param env [Hash] Hash of keys and values to set in `ENV`\n  # @param overwrite [Boolean|:warn] Overwrite existing `ENV` values\n  def update(env = {}, overwrite: false)\n    instrument(:update) do |payload|\n      diff = payload[:diff] = Dotenv::Diff.new do\n        ENV.update(env.transform_keys(&:to_s)) do |key, old_value, new_value|\n          # This block is called when a key exists. Return the new value if overwrite is true.\n          case overwrite\n          when :warn\n            # not printing the value since that could be a secret\n            warn \"Warning: dotenv not overwriting ENV[#{key.inspect}]\"\n            old_value\n          when true then new_value\n          when false then old_value\n          else raise ArgumentError, \"Invalid value for overwrite: #{overwrite.inspect}\"\n          end\n        end\n      end\n      diff.env\n    end\n  end\n\n  # Modify `ENV` for the block and restore it to its previous state afterwards.\n  #\n  # Note that the block is synchronized to prevent concurrent modifications to `ENV`,\n  # so multiple threads will be executed serially.\n  #\n  # @param env [Hash] Hash of keys and values to set in `ENV`\n  def modify(env = {}, &block)\n    SEMAPHORE.synchronize do\n      diff = Dotenv::Diff.new\n      update(env, overwrite: true)\n      block.call","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/bkeepers/dotenv/blob/34156bf400cd67387fa6ed9f146778f6a2f5f743/lib/dotenv.rb#L92-L128","documentation":"Dotenv.update accepts an `overwrite:` keyword that must be exactly `true`, `false`, or the symbol `:warn`; the case statement's else branch raises ArgumentError for any other value. dotenv deliberately does no type coercion, so truthy strings or integers are rejected instead of being interpreted. The raised message interpolates the offending value via inspect so you can immediately see what was passed.","triggerScenarios":"`Dotenv.update({\"KEY\" => \"v\"}, overwrite: \"true\")` (String from ENV/ARGV/YAML), `overwrite: 1`, or `overwrite: nil` from `overwrite: opts[:overwrite]` when the options hash lacks the key — anything not literally true, false, or :warn.","commonSituations":"Reading the flag from `ENV[\"OVERWRITE\"]` or CLI args and passing the string straight through; forwarding an optional options hash where a missing key yields nil; booleans serialized as strings in YAML/JSON config files.","solutions":["Pass a real boolean or the symbol :warn: `overwrite: true`, `overwrite: false`, or `overwrite: :warn`","Coerce external input before the call, e.g. `overwrite: %w[true 1 yes].include?(str.downcase)` or ActiveModel::Type::Boolean in Rails","Use `opts.fetch(:overwrite, false)` instead of `opts[:overwrite]` so an absent key defaults to false rather than nil"],"exampleFix":"# before\nDotenv.update(env, overwrite: ENV[\"DOTENV_OVERWRITE\"]) # \"true\" (String) -> ArgumentError\n\n# after\nDotenv.update(env, overwrite: %w[true 1 yes].include?(ENV[\"DOTENV_OVERWRITE\"].to_s.downcase))","handlingStrategy":"validation","validationCode":"overwrite = opts.fetch(:overwrite, false)\nraise ArgumentError, \"overwrite must be true, false, or :warn\" unless [true, false, :warn].include?(overwrite)\nDotenv.update(env, overwrite: overwrite)","typeGuard":"# Ruby: value-level guard for the overwrite flag\ndef valid_overwrite?(value)\n  [true, false, :warn].include?(value)\nend","tryCatchPattern":"begin\n  Dotenv.update(env, overwrite: flag)\nrescue ArgumentError\n  flag = false # safe default, then retry with a known-good value\n  retry\nend","preventionTips":["Never forward raw strings or nil from ENV/ARGV/YAML into keyword flags — coerce at the boundary","Use opts.fetch(:key, default) for optional flags so nil never reaches the API","Whitelist-validate enum-like options (true/false/:warn) as close to the caller as possible"],"tags":["argument-validation","ruby","dotenv","type-coercion","environment-variables"],"backgroundTag":"invalid-argument-value","analyzedSha":"34156bf400cd67387fa6ed9f146778f6a2f5f743","analyzedAt":"2026-08-21T19:00:36.354Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}