简体   繁体   中英

OS X, Elixir, Ecto, Crypto, MySQL

Trying out Elixir & Ecto (not Phoenix) in a sample app to help me learn the language.

Running my program results in the following error:

=INFO REPORT==== 7-Apr-2016::16:23:28 ===
    application: logger
    exited: stopped
    type: temporary
** (Mix) Could not start application tpos: exited in: Tpos.start(:normal, [])
    ** (EXIT) exited in: GenServer.call(#PID<0.164.0>, {:get_all, Tpos.Data.Models.ProfitCenter}, 5000)
        ** (EXIT) exited in: GenServer.call(#PID<0.163.0>, {:checkout, :run}, 5000)
            ** (EXIT) exited in: GenServer.call(#PID<0.168.0>, {:connect, [hostname: "localhost", timeout: 5000, otp_app: :tpos, repo: Tpos.Repo, adapter: Ecto.Adapters.MySQL, database: "tpos", username: "tpos", password: "tpos", port: 3306]}, 5000)
                ** (EXIT) an exception was raised:
                    ** (UndefinedFunctionError) undefined function :crypto.hash/2 (module :crypto is not available)
                        (crypto) :crypto.hash(:sha, "tpos")
                        (mariaex) lib/mariaex/protocol.ex:150: Mariaex.Protocol.mysql_native_password/2
                        (mariaex) lib/mariaex/protocol.ex:47: Mariaex.Protocol.dispatch/2
                        (mariaex) lib/mariaex/connection.ex:284: Mariaex.Connection.process/2
                        (mariaex) lib/mariaex/connection.ex:251: Mariaex.Connection.handle_info/2
                        (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4
                        (stdlib) gen_server.erl:681: :gen_server.handle_msg/5
                        (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

If I do a mix deps.clean --all and a mix.deps get and run the program again, it works. But only once. If I exit and attempt to run it again, I receive the above error.

The line that causes the error is:

data = Repo.all(ProfitCenter)

As I said, the first time through this runs fine and returns the expected data. It's only on subsequent runs that the error pops up.

From mix.exs:

defmodule Tpos.Mixfile do
  use Mix.Project

  def project do
    [app: :tpos,
     version: "0.0.1",
     elixir: "~> 1.2",
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps]
  end

  def application do
    [ applications: [:mariaex, :ecto],
      mod: { Tpos, [] } ]
  end

  defp deps do
    [
      {:credo, "~> 0.3", only: [:dev, :test]},
      {:mariaex, "~> 0.5.0"},
      {:ecto, "~> 1.1.5"},
      {:exactor, "~> 2.2.0"}
    ]
  end
end

I'm running OS X 10.11.1, and have tried several things to get it going based on advice like this .

Thoughts? Thanks!

The error states that you don't have :crypto module. You can verify that by running:

iex(1)> Application.start(:crypto)
:ok

If you get anything else than :ok , it means that your Erlang installation is not fully functional. It happens very often when you install Erlang via kerl . Kerl doesn't consider lack of openssl an error. It just skips crytpo libraries without warning.

To install fully functional Erlang with kerl you need to run:

brew install openssl
brew install unixodbc

After that create ~/.kerlrc file with following contents:

KERL_INSTALL_MANPAGES=yes
KERL_CONFIGURE_OPTIONS="--disable-hipe --enable-smp-support --enable-threads
                        --enable-kernel-poll --with-wx
                        --with-ssl=/usr/local/opt/openssl
                        --with-odbc=/usr/local/opt/unixodbc"

And try to reinstall Erlang. This config also adds wx-widgets which are handy if you want to run :observer application. Unixodbc also may come in handy, but less often.

If you are using different tool to install Erlang, you still need to point it to openssl path during compilation.

Alternatively, you can use packages provided by Erlang Solutions: https://www.erlang-solutions.com/resources/download.html They should install all required dependencies including crypto.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM