Sinc

Sinc

Dialyzer seems not to expect System.cmd to return a non-zero code

I ran dialyzer on this new code (with both Elixir 1.7 and 1.12) and am getting the error:

The pattern
variable_error

can never match, because previous clauses completely cover the type
:ok.

It points at the line in maybe_gen_certificates that does the put_error. I don’t understand why. The spec for generate_certificates should be correct, specifying :ok | {atom(), atom()}, and the with statement should be able to fail with {_, non_zero_integer} and return that as response. What am I missing?

  defp maybe_gen_certificates(config, false) do
    case generate_certificates() do
      :ok -> config
      error -> put_error(config, :certificate, error)
    end
  end

  @spec generate_certificates() :: :ok | {atom(), atom()}
  def generate_certificates do
    {key, cert} = keys()

    write_keys_permissions({key, cert})

    response =
      with {_, 0} <- System.cmd("openssl", ~w(genrsa -out #{key} 2048)),
           {_, 0} <- System.cmd("openssl", ~w(rsa -in #{key} -out #{cert} -outform PEM -pubout)),
           do: :ok

    reset_keys_permissions({key, cert})
    response
  end

Thanks! :smiley:

Marked As Solved

LostKobrakai

LostKobrakai

System.cmd and therefore generate_certificates returns {Collectable.t(), exit_status :: non_neg_integer()} not {atom(), atom()} in the case of a non zero exit status.

Last Post!

Sinc

Sinc

That worked. Thanks.

I wonder why this doesn’t report that the spec doesn’t match the success typing of the function. That would have pointed me directly to the problem. I would think that if it was smart enough to know that the failure couldn’t actually return {atom, atom} that it would complain about what it should be returning. Or even recognize that there was a second option for return that the error would catch.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement