简体   繁体   English

Elixir-在Mac上设置MIX_ENV会产生FunctionClauseError

[英]Elixir - setting MIX_ENV on a Mac yields FunctionClauseError

I'm having trouble getting my Elixir apps to read the MIX_ENV variable from the local environment on my Mac. 我无法让Elixir应用程序从Mac上的本地环境读取MIX_ENV变量。 For example, running the command 例如,运行命令

$ MIX_ENV=prod iex -S mix

throws the following error: 引发以下错误:

** (FunctionClauseError) no function clause matching in String.split/3    

    The following arguments were given to String.split/3:

        # 1
        nil

        # 2
        " "

        # 3
        []

    Attempted function clauses (showing 4 out of 4):

        def split(string, %Regex{} = pattern, options) when is_binary(string)
        def split(string, "", options) when is_binary(string)
        def split(string, pattern, []) when is_tuple(pattern) or is_binary(string)
        def split(string, pattern, options) when is_binary(string)

    (elixir) lib/string.ex:407: String.split/3
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:240: :erl_eval.expr/5
    (stdlib) erl_eval.erl:232: :erl_eval.expr/5
    (stdlib) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:411: :erl_eval.expr/5
    (stdlib) erl_eval.erl:126: :erl_eval.exprs/5

This also occurs if I set the MIX_ENV in a separate step. 如果我在单独的步骤中设置MIX_ENV ,也会发生这种情况。

From the documentation at https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html , it looks to me like I'm doing this correctly, but it would seem that I'm not. 根据https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html上的文档,在我看来我做得正确,但似乎我在不。 Is there a different way that I need to set this? 我需要设置其他方式吗?

As noted, I'm working on a Mac, Mojave 10.14.6, and my Elixir version is 1.8.1. 如前所述,我正在Mac上运行Mojave 10.14.6,而我的Elixir版本是1.8.1。

I would check your configuration. 我会检查您的配置。 For me a lot of times this comes from prod expecting an environment variable to be set. 对我而言,很多时候这是由于期望设置环境变量而产生的。

My guess is you have some code that looks something like this: 我的猜测是您有一些看起来像这样的代码:

:my_app
|> Application.get_env(:some_config)
|> String.split(" ")
|> do_something_else()

Then in your config/config.exs or config/dev.exs you probably have something like this: 然后,在您的config/config.exsconfig/dev.exs您可能会有类似以下内容:

config :my_app, :some_config, "some value"

Then your config/prod.exs might have something like this: 然后,您的config/prod.exs可能具有以下内容:

config :my_app, :some_config, System.get_env("MY_ENV_VAR")

If MY_ENV_VAR is not set, but you run your app in prod (for example doing MIX_ENV=prod iex -S mix ), Application.get_env(:my_app, :some_config) will return nil , which you would then be trying to split like it's a string. 如果未设置MY_ENV_VAR ,但是您在产品中运行您的应用程序(例如,执行MIX_ENV=prod iex -S mix ),则Application.get_env(:my_app, :some_config)将返回nil ,然后您将尝试像这样拆分一个字符串。

This is just a guess based on my experience, but your stack trace would lead me to believe I'm wrong. 这只是基于我的经验的猜测,但是您的堆栈跟踪会使我相信我错了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Heroku中为Phoenix Framework设置MIX_ENV - Setting MIX_ENV in Heroku for Phoenix Framework Windows:Elixir phoenix MIX_ENV = prod:该术语无法识别 - Windows: Elixir phoenix MIX_ENV=prod : The term is not recognized 凤凰服务器上的MIX_ENV = prod在PORT = 80时崩溃 - MIX_ENV=prod on a Phoenix server crashes on starting with PORT=80 仅当MIX_ENV最初未设置为“test”时才加载混合依赖项标记为test - Loading mix dependencies marked as test only when the MIX_ENV was not originally set to “test” 无法将“ MIX_ENV”识别为内部或外部命令,可操作程序或批处理文件 - 'MIX_ENV' is not recognized as an internal or external command, operable program or batch file ** (CaseClauseError) 没有 case 子句匹配::eacces - 使用 MIX_ENV=prod 构建版本 - ** (CaseClauseError) no case clause matching: :eacces - Building release with MIX_ENV=prod Elixir :( FunctionClauseError)没有函数子句匹配 - Elixir: (FunctionClauseError) no function clause matching 从Elixir调用:wxFrame.new时发生FunctionClauseError - FunctionClauseError when calling :wxFrame.new from Elixir Phoenix 1.3 Elixir jsonapi(FunctionClauseError)在render / 2中没有匹配的函数子句 - Phoenix 1.3 Elixir jsonapi (FunctionClauseError) no function clause matching in render/2 Elixir 混合自动确认 - Elixir mix auto acknowledge
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM