     raise ArgumentError, "invalid base #{inspect(base)}"
   end
 
-  def parse(binary, base) do
+  def parse(binary, base) when is_binary(binary) do
     case count_digits(binary, base) do
       0 ->
         :error

    end
  end

  defp count_digits(<<sign, rest::binary>>, base) when sign in '+-' do
    case count_digits_nosign(rest, base, 1) do
      1 -> 0
      count -> count
    end
  end

  defp count_digits(<<rest::binary>>, base) do
    count_digits_nosign(rest, base, 0)
  end


      char <- chars do
    digit = char + diff

    defp count_digits_nosign(<<unquote(char), rest::bits>>, base, count)
         when base > unquote(digit) do
      count_digits_nosign(rest, base, count + 1)
    end
  end

  defp count_digits_nosign(<<_::bits>>, _, count), do: count

  # TODO: Remove Integer.to_string/1 once the minimum supported version is
  #       Erlang/OTP 22, since it is covered by the now BIF Integer.to_string/2.
