JakeBecker / vscode-elixir-ls

Elixir language support and debugger for VS Code, powered by ElixirLS.
391 stars 42 forks source link

Unable to load Bcrypt when Debugging #25

Closed deybhayden closed 6 years ago

deybhayden commented 6 years ago

Running the default mix task (just compiling) results in the error below for my project. I have Erlang 20 and can run the same commands successfully from the command line. Any suggestions for this? Found another similar issue for IntelliJ - https://github.com/KronicDeth/intellij-elixir/issues/891 - he switched crypto packages, but I'd rather not do that for just editor tooling? Thanks!

** (RuntimeError) An error occurred when loading Bcrypt.
Make sure you have a C compiler and Erlang 20 installed.
If you are not using Erlang 20, either upgrade to Erlang 20 or
use version 0.12 of bcrypt_elixir.
See the Comeonin wiki for more information.
    lib/bcrypt/base.ex:14: Bcrypt.Base.init/0
    (kernel) code_server.erl:1333: anonymous fn/1 in :code_server.handle_on_load/5
(Debugger) Initialization failed because an exception was raised:
    ** (MatchError) no match of right hand side value: {:error, :on_load_failure}
        int.erl:531: anonymous fn/3 in :int.load/2
        int.erl:527: :int.load/2
        (elixir) lib/enum.ex:1255: Enum."-map/2-lists^map/1-0-"/2
        (elixir) lib/enum.ex:1255: Enum."-map/2-lists^map/1-0-"/2
        (debugger) lib/debugger/server.ex:468: ElixirLS.Debugger.Server.initialize/1
JakeBecker commented 6 years ago

The debugger can't handle NIFs, so you'll need to exclude modules with NIFs in your launch configuration. Try adding the option "excludeModules": ["Bcrypt.Base"] in launch.json.

JakeBecker commented 6 years ago

I just tried it. You actually need to do "excludeModules": [":bcrypt_nif"].

deybhayden commented 6 years ago

Thank you - your first suggestion worked in that the server started, but :bcrypt_nif doesn't. It looked like my phoenix server was running, but I couldn't actually hit the localhost url though.

JakeBecker commented 6 years ago

Hm. Being unable to hit the Phoenix endpoint may be unrelated to the NIF issue. Can you confirm whether you can debug it without the bcrypt library?

deybhayden commented 6 years ago

Aha, think I got it. I had to take out "startApps" from my phx.server command. I think bcrypt exclusion worked - but then after the server started, vscode froze, then I got Debug adapter process has terminated unexpectedly.

JakeBecker commented 6 years ago

Ah, yeah, startApps is required for Phoenix tests but breaks Phoenix server. It's tricky!

JakeBecker commented 6 years ago

Hm. Sorry for continuing to open and close this issue. I'm not properly awake yet.

Debugging the silent debugger failures is a pain. Can you post your code somewhere for me to look at?

deybhayden commented 6 years ago

I think you can close it one more time - our app has a configuration for starting the webpack dev server as well, and I was launching it too in the debugger. When I turned that off, it started working šŸŽ‰ . I'm not sure if that's a common practice or not, but we do something like BUILD_CLIENT=true mix phx.server to kick off a webpack server proc. Think that threw a wrench in everything.

JakeBecker commented 6 years ago

Are you launching webpack via the watchers section of your Phoenix config? It'd be good to know if that breaks the debugger.

deybhayden commented 6 years ago

Yes:

watchers = case {System.get_env("BUILD_CLIENT"), IEx.started?} do
  {build?, _} when build? in [nil, false] -> []
  {_, true} -> ["npm": ["run", "start-iex", cd: asset_dir]]
  {_, _}    -> ["npm": ["start", cd: asset_dir]]
end
JakeBecker commented 6 years ago

Got it. Thanks!

deybhayden commented 6 years ago

Thank you! Great project, love actually being able to run a debugger for Elixir! šŸ™‡

mhussa commented 6 years ago

Sorry to do this but, I have a similar but different situation. I get this error when my code attempts to use bcrypt.

(exit) an exception was raised: (ErlangError) Erlang error: :not_loaded :erlang.nif_error(:not_loaded) (comeonin) Elixir.Comeonin.Bcrypt.erl:142: Comeonin.Bcrypt.bf_init/3 (comeonin) Elixir.Comeonin.Bcrypt.erl:166: Comeonin.Bcrypt.bcrypt/4 (comeonin) Elixir.Comeonin.Bcrypt.erl:159: Comeonin.Bcrypt.hashpw/2 (comeonin) Elixir.Comeonin.Bcrypt.erl:118: Comeonin.Bcrypt.checkpw/2

I tried both types of excludeModules, deleted .elixir_ls and _build. rebuilt it, same thing. Any ideas? Its a phoenix project using brunch.

I should add though that its an umbrella phoenix web app. I created a task: "phx.server" to start it using the umbrella dir as the "projectDir".

Thankyou for the work you've put into this btw, was amazed to see variables in an interactive editor and not iex.

mhussa commented 6 years ago

I upgraded my comeonin dependancy to v4.0 and got past this error. Got another issue but I'll try to work it through first this time. Thanks anyway.