4

I am using the Erlang language plugin for vscode. I created a new rebar3 app and created a simple app that doesnt use a supervisor:

-module(test_app_app).

-behaviour(application).

-export([start/2, stop/1]).

start(_StartType, _StartArgs) ->
    load_file("input.txt").

stop(_State) ->
    ok.

load_file(Filename) ->
    case file:read_file(Filename) of
        {ok, Bin} ->
            Bin;
        {error, Reason} ->
            erlang:error(Reason)
    end.

I have configured a launch.json file like so:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch erlang",
            "type": "erlang",
            "request": "launch",
            "cwd": "${workspaceRoot}",
            "arguments": "-s test_app_app start",
            "preLaunchTask": "rebar3 compile"
        }
    ]
}

and a tasks.json for the compile:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "rebar3 compile",
            "type": "shell",
            "command": "rebar3 compile",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": "$erlang"
        }
    ]
}

When I hit F5 I get the following output:

compiling erlang bridge to '/home/peter/.vscode/extensions/pgourlain.erlang-0.8.1/_build/default/lib/ebin'
Compiling arguments file  "/tmp/bp_1454870.erl"
Compile result: sucess 
Module bp_1454870 loaded
{"init terminating in do_boot",{undef,[{t
est_app_app,start,[],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ({undef,[{test_app_app,start,[],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]})

Crash dump is being written to: erl_crash.dump...
done
erl exit code:1
erl exit with code 1

Does anyone have a clue as to why this isnt working for me?

Peter Short
  • 762
  • 6
  • 17

1 Answers1

1

The problem is in your launch.json. You try to run a function start/0 from module test_app_app and such function does not exist.

Try to use

"arguments": "-eval \"application:start(test_app)\""
Wojtek Surowka
  • 20,535
  • 4
  • 44
  • 51
  • Thank you very much :) That worked for me! So I was trying to use the -s parameter before, but getting no result. Is eval the better way to do this? Is there an equivalent to the above using -s? I tried `-s application start [] [] before` – Peter Short Oct 16 '21 at 08:28
  • @PeterShort I do not think it is possible to use `-s` for this. Erlang documentation for `-s` says that the function we call should be either of arity 0 or of arity 1. In the latter case the function should accept the provided arguments as list of atoms. The `application:start` does not accept a list of atoms as argument. – Wojtek Surowka Oct 18 '21 at 14:55