erlang-ls / erlang_ls

The Erlang Language Server
https://erlang-ls.github.io/
Apache License 2.0
630 stars 136 forks source link

erl_lint:format_error function clause when generating diagnostics for my module #760

Closed rocveralfre closed 4 years ago

rocveralfre commented 4 years ago

Describe the bug On the OnSave event, Visual Studio shows an endless "Compiler (__module_name__): 0/1"

In reality, my debug logs show a crash in the format of:

2020-06-01 16:21:08 =ERROR REPORT====
** Generic server <0.273.0> terminating 
** Last message in was exec
** When Server state == #{config => #{entries => [<<"file:///Users/veralfre/Documents/github/core3_gardena/src/gardena_sup.erl">>],on_complete => #Fun<els_diagnostics.1.49123447>,on_error => #Fun<els_background_job.3.63323040>,task => #Fun<els_diagnostics.0.49123447>,title => <<"Compiler (gardena_sup)">>},current => 0,internal_state => undefined,progress_enabled => true,show_percentages => true,spinning_wheel => undefined,step => 100.0,token => <<"dc56d615-bae9-46d0-b8c8-35d4b61d16a2">>,total => 1}
** Reason for termination ==
** {function_clause,[{erl_lint,format_error,[[73,115,115,117,101,32,105,110,32,105,110,99,108,117,100,101,100,32,102,105,108,101,32,40,"692",41,58,32,[123,["unused_function",44,[123,["restart_child",44,"3"],125]],125]]],[{file,"erl_lint.erl"},{line,157}]},{els_compiler_diagnostics,diagnostic,4,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,158}]},{els_compiler_diagnostics,'-diagnostics/3-lc$^1/1-1-',5,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,122}]},{els_compiler_diagnostics,'-diagnostics/3-lc$^0/1-0-',4,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,129}]},{els_compiler_diagnostics,diagnostics,3,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,130}]},{els_compiler_diagnostics,load_dependency,2,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,304}]},{els_compiler_diagnostics,'-compile_file/2-lc$^0/1-0-',2,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,274}]},{els_compiler_diagnostics,compile_file,2,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,274}]}]}
2020-06-01 16:21:08 =CRASH REPORT====
  crasher:
    initial call: els_background_job:init/1
    pid: <0.273.0>
    registered_name: []
    exception error: {function_clause,[{erl_lint,format_error,[[73,115,115,117,101,32,105,110,32,105,110,99,108,117,100,101,100,32,102,105,108,101,32,40,"692",41,58,32,[123,["unused_function",44,[123,["restart_child",44,"3"],125]],125]]],[{file,"erl_lint.erl"},{line,157}]},{els_compiler_diagnostics,diagnostic,4,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,158}]},{els_compiler_diagnostics,'-diagnostics/3-lc$^1/1-1-',5,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,122}]},{els_compiler_diagnostics,'-diagnostics/3-lc$^0/1-0-',4,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,129}]},{els_compiler_diagnostics,diagnostics,3,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,130}]},{els_compiler_diagnostics,load_dependency,2,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,304}]},{els_compiler_diagnostics,'-compile_file/2-lc$^0/1-0-',2,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,274}]},{els_compiler_diagnostics,compile_file,2,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,274}]}]}
    ancestors: [els_background_job_sup,els_sup,<0.174.0>]
    message_queue_len: 0
    messages: []
    links: [<0.194.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 17731
    stack_size: 27
    reductions: 35652
  neighbours:
2020-06-01 16:21:08 =SUPERVISOR REPORT====
     Supervisor: {local,els_background_job_sup}
     Context:    child_terminated
     Reason:     {function_clause,[{erl_lint,format_error,[[73,115,115,117,101,32,105,110,32,105,110,99,108,117,100,101,100,32,102,105,108,101,32,40,"692",41,58,32,[123,["unused_function",44,[123,["restart_child",44,"3"],125]],125]]],[{file,"erl_lint.erl"},{line,157}]},{els_compiler_diagnostics,diagnostic,4,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,158}]},{els_compiler_diagnostics,'-diagnostics/3-lc$^1/1-1-',5,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,122}]},{els_compiler_diagnostics,'-diagnostics/3-lc$^0/1-0-',4,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,129}]},{els_compiler_diagnostics,diagnostics,3,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,130}]},{els_compiler_diagnostics,load_dependency,2,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,304}]},{els_compiler_diagnostics,'-compile_file/2-lc$^0/1-0-',2,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,274}]},{els_compiler_diagnostics,compile_file,2,[{file,"/Users/robert.aloi/git/github/erlang-ls/vscode/erlang_ls/src/els_compiler_diagnostics.erl"},{line,274}]}]}
     Offender:   [{pid,<0.273.0>},{id,els_background_job},{mfargs,{els_background_job,start_link,undefined}},{restart_type,temporary},{shutdown,5000},{child_type,worker}]

To Reproduce This is my current erlang_ls.config:

deps_dir:
  - "deps/*"
  - "../core3/*"

diagnostics:
  enabled:
    - xref
  disabled:
    - compiler
    - dialyzer
    - elvis

include_dirs:
  - "./include"

Expected behavior I voluntarely made a mistake in the code to check what Visual studio shows in that case, I would expect to see the line highlighted with the error.

Actual behavior It endlessly waits for the "Compiler" step to return (which never does of course due to the crash).

Context

rocveralfre commented 4 years ago

It seems related to a

-behavior(supervisor). 

That was in my source file.. By removing the behavior declaration erlang_ls compiled successfully the file.

alanz commented 4 years ago

Can you try with current master? It may be fixed by https://github.com/erlang-ls/erlang_ls/pull/755

robertoaloi commented 4 years ago

Hi @rocveralfre and thanks for getting in touch!

This should already be solved in 0.4.1 (available in the VSCode marketplace via 0.0.14) via #745 and #755. Please upgrade to the latest available version of the extension and let us know if that does not help.

Have a great day!

rocveralfre commented 4 years ago

Thanks for the quick answer.

I will try to check tomorrow morning and report in case of further errors.

Thanks for all the work I wish I could help you somehow but for now we'll try to test as much as possible with our production code.

In case is there anything else I could help you please let me know! :)