Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore compilation warnings when running phoenix server

I'm trying to run phoenix server from the command line with iex -S mix phx.server but I keep getting warnings on compilation about unused variables.

Compilation failed due to warnings while using the --warnings-as-errors option

I don't care about these warnings as i am in the middle of development and these vars will eventually be used or tossed out. I have tried passing -h and other sensible options, but none of them work and I can't find anything in the docs about how to get phx.server to pass or override options to the compiler.

I've seen these docs and they haven't helped

  • https://hexdocs.pm/mix/Mix.Tasks.Run.html
  • https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Server.html

I have tried passing the --no-compile option but this is a no-go since it leaves me unable to recompile during development. I am currently using IO.inspect to call the vars and this seems to be "good enough" for me to pass the unused vars check, but I would rather be able to disable this flag in the compiler rather than littering my code with IO.inspect

like image 769
Ben Glasser Avatar asked Dec 18 '22 19:12

Ben Glasser


2 Answers

The error message is pretty clear on that:

Compilation failed due to warnings while using the --warnings-as-errors option

You have this specific flag enabled on the compiler, it returns a non-zero exit code on warnings. Since you're not passing the option manually in the command-line, it's possible that it's being:

  • Set via an ENV variable (possibly by an Elixir version manager)
  • Being passed in a mix alias or task
  • But most probably it's hardcoded in your Mixfile under elixirc_options. You can disable it like this:

    # mix.exs
    elixirc_options: [warnings_as_errors: false]
    

On a side note, to get help on compiler options, you should use elixirc:

± % elixirc --help
Usage: elixirc [elixir switches] [compiler switches] [.ex files]

  -o                        The directory to output compiled files

  --help, -h                Prints this message and exits
  --ignore-module-conflict  Does not emit warnings if a module was previously defined
  --no-debug-info           Does not attach debug info to compiled modules
  --no-docs                 Does not attach documentation to compiled modules
  --verbose                 Prints compilation status
  --version, -v             Prints Elixir version and exits
  --warnings-as-errors      Treats warnings as errors and return non-zero exit code

** Options given after -- are passed down to the executed code
** Options can be passed to the Erlang runtime using ELIXIR_ERL_OPTIONS
** Options can be passed to the Erlang compiler using ERL_COMPILER_OPTIONS

Also see: Get the compiler to exit if a compile-time warning is raised

like image 97
Sheharyar Avatar answered Feb 27 '23 15:02

Sheharyar


If you run mix compile --warnings-as-errors=false first, then you can run iex -S mix phx.server without issues as it will already be compiled and should just start up.

like image 45
Tyler Hawkins Avatar answered Feb 27 '23 15:02

Tyler Hawkins