     end
   end
 
-  def get_docs(binpath, kind) when is_binary(binpath) do
+  def get_docs(binpath, kind) when is_binary(binpath) and kind in @doc_kinds do
     do_get_docs(String.to_char_list(binpath), kind)
   end
 

  # unsupported chunk version
  defp lookup_docs(_, _), do: nil

  @doc_sections [:docs, :moduledoc, :callback_docs, :type_docs]

  defp do_lookup_docs(docs, :all), do: docs
  defp do_lookup_docs(docs, kind) when kind in @doc_sections,
    do: Keyword.get(docs, kind)

  ## Helpers

      iex> String.split(text, "\n") |> Enum.at(0)
      "Converts an atom to a char list."

      # Module doesn't exist
      iex> docs = Code.get_docs(ModuleNotGood, :all)
      nil

  """
  @doc_kinds [:docs, :moduledoc, :callback_docs, :type_docs, :all]

  def get_docs(module, kind) when is_atom(module) and kind in @doc_kinds do
    case :code.get_object_code(module) do
      {_module, bin, _beam_path} ->
        do_get_docs(bin, kind)
