erlang / rebar3

Erlang build tool that makes it easy to compile and test Erlang applications and releases.
http://www.rebar3.org
Apache License 2.0
1.69k stars 515 forks source link

rebar3 crashing with strange error when specifying a lager.config file for the shell #1719

Closed lfmunoz closed 6 years ago

lfmunoz commented 6 years ago

Pre-Check

Willing and interested in helping fix the issue.

I am trying to add a lager.config file to my current project that uses lager so that I can control the format of the output log messages.

Environment

rebar3 report "shell --apps erl_audio --config lager.config"                                         
Rebar3 report                                     
 version 3.5.0                                    
 generated at 2018-02-24T02:06:08+00:00           
=================                                 
Please submit this along with your issue at https://github.com/erlang/rebar3/issues (and feel free to edit out private information, if any)                                                               
-----------------                                 
Task: shell                                       
Entered as:                                       
  shell --apps erl_audio --config lager.config    
-----------------                                 
Operating System: x86_64-pc-linux-gnu             
ERTS: Erlang/OTP 20 [erts-9.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:0] [kernel-poll:false]                                                                                            
Root Directory: /usr/lib/erlang                   
Library directory: /usr/lib/erlang/lib            
-----------------                                 
Loaded Applications:                              
bbmustache: 1.3.0                                 
certifi: 2.0.0                                    
cf: 0.2.2                                         
common_test: 1.15.1                               
compiler: 7.1.1                                   
crypto: 4.0                                       
cth_readable: 1.3.2                               
dialyzer: 3.2.1                                   
edoc: 0.9                                         
erlware_commons: 1.0.4                            
eunit: 2.3.3                                      
eunit_formatters: 0.5.0                           
getopt: 1.0.1                                     
inets: 6.4                                        
kernel: 5.3.1                                     
providers: 1.7.0                                  
public_key: 1.4.1                                 
relx: 3.24.3                                      
sasl: 3.0.4                                       
snmp: 5.2.6                                       
ssl_verify_fun: 1.1.3                             
stdlib: 3.4.1                                     
syntax_tools: 2.1.2                               
tools: 2.10.1                                     

-----------------                                 
Escript path: /usr/local/bin/rebar3               
Providers:                                        
  app_discovery as clean compile compile cover ct deps dialyzer do edoc escriptize eunit get-deps help install install_deps list lock new path pkgs release relup report shell state tar tree unlock update upgrade upgrade upgrade version xref            
#rebar3 report DEBUG=1 rebar3 shell --apps erl_audio --config lager.config         

Current behaviour

DEBUG=1 rebar3 shell --apps erl_audio --config lager.config                                                                                                                                               
===> Expanded command sequence to be run: [{default,app_discovery},                                                                                                                                       
                                                  {default,install_deps},                                                                                                                                 
                                                  {default,lock},                                                                                                                                         
                                                  {default,compile},                                                                                                                                      
                                                  {default,shell}]                                                                                                                                        
===> Provider: {default,app_discovery}                                                                                                                                                                    
===> Evaluating config script "/home/luis/projects/erl_audio/_build/default/lib/jiffy/rebar.config.script"                                                                                                
===> Evaluating config script "/home/luis/projects/erl_audio/_build/default/lib/jiffy/rebar.config.script"                                                                                                
===> Evaluating config script "/home/luis/projects/erl_audio/_build/default/lib/jsx/rebar.config.script"                                                                                                  
===> Evaluating config script "/home/luis/projects/erl_audio/_build/default/lib/jsx/rebar.config.script"                                                                                                  
===> Evaluating config script "/home/luis/projects/erl_audio/_build/default/lib/lager/rebar.config.script"                                                                                                
===> Evaluating config script "/home/luis/projects/erl_audio/_build/default/lib/lager/rebar.config.script"                                                                                                
===> Provider: {default,install_deps}                                                                                                                                                                     
===> Verifying dependencies...                                                                                                                                                                            
===> sh info:                                                                                                                                                                                             
        cwd: "/home/luis/projects/erl_audio"                                                                                                                                                              
        cmd: git rev-parse --short=7 -q HEAD                                                                                                                                                              

===>    opts: [{cd,"/home/luis/projects/erl_audio/_build/default/lib/cowboy"}]                                                                                                                            

===> Port Cmd: git rev-parse --short=7 -q HEAD                                                                                                                                                            
Port Opts: [{cd,"/home/luis/projects/erl_audio/_build/default/lib/cowboy"},                                                                                                                               
            exit_status,                                                                                                                                                                                  
            {line,16384},                                                                                                                                                                                 
            use_stdio,stderr_to_stdout,hide,eof]                                                                                                                                                          

===> Comparing git ref 572d380 with 572d380                                                                                                                                                               
===> sh info:                                                                                                                                                                                             
        cwd: "/home/luis/projects/erl_audio"                                                                                                                                                              
        cmd: git rev-parse --short=7 -q HEAD                                                                                                                                                              

===>    opts: [{cd,"/home/luis/projects/erl_audio/_build/default/lib/jiffy"}]                                                                                                                             

===> Port Cmd: git rev-parse --short=7 -q HEAD                                                                                                                                                            
Port Opts: [{cd,"/home/luis/projects/erl_audio/_build/default/lib/jiffy"},                                                                                                                                
            exit_status,                                                                                                                                                                                  
            {line,16384},                                                                                                                                                                                 
            use_stdio,stderr_to_stdout,hide,eof]                                                                                                                                                          

===> Comparing git ref 031f9db with 031f9db                                                                                                                                                               
===> Evaluating config script "/home/luis/projects/erl_audio/_build/default/lib/jiffy/rebar.config.script"                                                                                                
===> sh info:                                                                                                                                                                                             
        cwd: "/home/luis/projects/erl_audio"                                                                                                                                                              
        cmd: git rev-parse --short=7 -q HEAD           

........ (SKIPPED A BUNCH OF TEXT).......

===> sh info:                                                                                                                                                                                             
        cwd: "/home/luis/projects/erl_audio"                                                                                                                                                              
        cmd: git --git-dir="/home/luis/projects/erl_audio/_build/default/lib/jiffy/.git" rev-parse --verify HEAD                                                                                          

===>    opts: [{use_stdout,false},                                                                                                                                                                        
                       {debug_abort_on_error,                                                                                                                                                             
                           "Locking of git dependency failed in /home/luis/projects/erl_audio/_build/default/lib/jiffy"}]                                                                                 

===> Port Cmd: git --git-dir="/home/luis/projects/erl_audio/_build/default/lib/jiffy/.git" rev-parse --verify HEAD                                                                                        
Port Opts: [exit_status,{line,16384},use_stdio,stderr_to_stdout,hide,eof]                                                                                                                                 

===> sh info:                                                                                                                                                                                             
        cwd: "/home/luis/projects/erl_audio"                                                                                                                                                              
        cmd: git --git-dir="/home/luis/projects/erl_audio/_build/default/lib/cowboy/.git" rev-parse --verify HEAD                                                                                         

===>    opts: [{use_stdout,false},                                                                                                                                                                        
                       {debug_abort_on_error,                                                                                                                                                             
                           "Locking of git dependency failed in /home/luis/projects/erl_audio/_build/default/lib/cowboy"}]                                                                                

===> Port Cmd: git --git-dir="/home/luis/projects/erl_audio/_build/default/lib/cowboy/.git" rev-parse --verify HEAD                                                                                       
Port Opts: [exit_status,{line,16384},use_stdio,stderr_to_stdout,hide,eof]                                                                                                                                 

===> Provider: {default,compile}                                                                                                                                                                          
===> run_hooks("/home/luis/projects/erl_audio", pre_hooks, compile) -> no hooks defined                                                                                                                   

===> Compiling erl_audio                                                                                                                                                                                  
===> run_hooks("/home/luis/projects/erl_audio", pre_hooks, compile) -> no hooks defined                                                                                                                   

===> run_hooks("/home/luis/projects/erl_audio", pre_hooks, erlc_compile) -> no hooks defined                                                                                                              

===> erlopts [debug_info,{parse_transform,lager_transform}]
===> files to compile ["/home/luis/projects/erl_audio/_build/default/lib/erl_audio/src/audio_ets.erl",
                              "/home/luis/projects/erl_audio/_build/default/lib/erl_audio/src/audio_proc.erl",
                              "/home/luis/projects/erl_audio/_build/default/lib/erl_audio/src/erl_audio_sup.erl",
                              "/home/luis/projects/erl_audio/_build/default/lib/erl_audio/src/globals.erl",
                              "/home/luis/projects/erl_audio/_build/default/lib/erl_audio/src/erl_audio_app.erl",
                              "/home/luis/projects/erl_audio/_build/default/lib/erl_audio/src/user/user_ets.erl",
                              "/home/luis/projects/erl_audio/_build/default/lib/erl_audio/src/user/user_proc.erl"]
===> run_hooks("/home/luis/projects/erl_audio", post_hooks, erlc_compile) -> no hooks defined

===> run_hooks("/home/luis/projects/erl_audio", pre_hooks, app_compile) -> no hooks defined

===> run_hooks("/home/luis/projects/erl_audio", post_hooks, app_compile) -> no hooks defined

===> run_hooks("/home/luis/projects/erl_audio", post_hooks, compile) -> no hooks defined             

===> run_hooks("/home/luis/projects/erl_audio", post_hooks, compile) -> no hooks defined             

===> Provider: {default,shell}                    
Erlang/OTP 20 [erts-9.0.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:0] [kernel-poll:false]                                                                                                  

Eshell V9.0.4  (abort with ^G)                    
1> ===> No script_file specified.                 
===> Found shell apps from command line option.   
===> Found config from command line option.       
===> Loading configuration from "/home/luis/projects/erl_audio/lager.config"                         
===> Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump    
===> Uncaught error: function_clause              
===> Stack trace to the error location:           
[{lists,flatmap,                                  
     [#Fun<rebar_file_utils.0.108822782>,         
      {lager,                                     
          [{log_root,"/var/log/hello"},           
           {handlers,                             
               [{lager_console_backend,[{level,info}]},                                              
                {lager_file_backend,[{file,"error.log"},{level,error}]},                             
                {lager_file_backend,[{file,"console.log"},{level,info}]}]}]}],                       
     [{file,"lists.erl"},{line,1249}]},           
 {rebar_file_utils,consult_config,2,              
     [{file,                                      
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_file_utils.erl"},           
      {line,76}]},                                
 {rebar_prv_shell,reread_config,1,                
     [{file,                                      
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_prv_shell.erl"},            
      {line,344}]},                               
 {rebar_prv_shell,maybe_boot_apps,1,              
     [{file,                                      
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_prv_shell.erl"},            
      {line,278}]},                               
 {rebar_prv_shell,shell,1,                        
     [{file,                                      
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_prv_shell.erl"},            
      {line,112}]},                               
 {rebar_prv_shell,do,1,                           
     [{file,                                      
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_prv_shell.erl"},            
      {line,88}]},                                
 {rebar_core,do,2,                                
     [{file,                                      
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_core.erl"},                 
      {line,154}]},                               
 {rebar3,main,1,                                  
     [{file,                                      
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar3.erl"},                     
      {line,66}]}]                                
===> When submitting a bug report, please include the output of `rebar3 report "your command"`       

Expected behaviour

Expected to rebar3 to run my application with lager.config file load, instead I get a crash.

Doesn't work:

rebar3 shell --apps erl_audio --config lager.config

Works:

rebar3 shell --apps erl_audio

I'm sure my lager.config file is correct as I copied it directly from lager documentation. I tried various versions some which I am using on other projects that work.

{lager, [
  {log_root, "/var/log/hello"},
  {handlers, [
    {lager_console_backend, [{level, info}]},
    {lager_file_backend, [{file, "error.log"}, {level, error}]},
    {lager_file_backend, [{file, "console.log"}, {level, info}]}
  ]}
]}.

The rebar3.crashdump

Error: function_clause
[{lists,flatmap,
     [#Fun<rebar_file_utils.0.108822782>,
      {lager,
          [{log_root,"/var/log/hello"},
           {handlers,
               [{lager_console_backend,[{level,info}]},
                {lager_file_backend,[{file,"error.log"},{level,error}]},
                {lager_file_backend,[{file,"console.log"},{level,info}]}]}]}],
     [{file,"lists.erl"},{line,1249}]},
 {rebar_file_utils,consult_config,2,
     [{file,
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_file_utils.erl"},
      {line,76}]},
 {rebar_prv_shell,reread_config,1,
     [{file,
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_prv_shell.erl"},
      {line,344}]},
 {rebar_prv_shell,maybe_boot_apps,1,
     [{file,
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_prv_shell.erl"},
      {line,278}]},
 {rebar_prv_shell,shell,1,
     [{file,
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_prv_shell.erl"},
      {line,112}]},
 {rebar_prv_shell,do,1,
     [{file,
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_prv_shell.erl"},
      {line,88}]},
 {rebar_core,do,2,
     [{file,
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar_core.erl"},
      {line,154}]},
 {rebar3,main,1,
     [{file,
          "/home/tristan/Devel/rebar3/_build/default/lib/rebar/src/rebar3.erl"},
      {line,66}]}]
lfmunoz commented 6 years ago

I created a super simple project to reproduce the problem...

https://github.com/lfmunoz/rebar3_bug1719

Look at the Makefile in the root directory of the project

Works:

make server 

Produces the reported error:

make server-config
ferd commented 6 years ago

Config files of that format require to be put in a list. Instead of

{lager, [
  {log_root, "/var/log/hello"},
  {handlers, [
    {lager_console_backend, [{level, info}]},
    {lager_file_backend, [{file, "error.log"}, {level, error}]},
    {lager_file_backend, [{file, "console.log"}, {level, info}]}
  ]}
]}.

Use:

[
 {lager, [
  {log_root, "/var/log/hello"},
  {handlers, [
    {lager_console_backend, [{level, info}]},
    {lager_file_backend, [{file, "error.log"}, {level, error}]},
    {lager_file_backend, [{file, "console.log"}, {level, info}]}
  ]}
 ]}
].

And then everything will work fine.