Skip to content

Commit dcc6784

Browse files
committed
rescue error when invalid env config is passes from client
1 parent 7b29d2b commit dcc6784

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

apps/elixir_ls_debugger/lib/debugger/server.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,19 @@ defmodule ElixirLS.Debugger.Server do
17021702
end
17031703

17041704
defp set_env_vars(env) when is_map(env) do
1705-
for {k, v} <- env, do: System.put_env(k, v)
1705+
try do
1706+
System.put_env(env)
1707+
rescue
1708+
e ->
1709+
Output.debugger_console(
1710+
"Cannot set environment variables to #{inspect(env)}: #{Exception.message(e)}"
1711+
)
1712+
1713+
Output.debugger_important(
1714+
"Invalid `env` in launch configuration. Expected a map with string key value pairs, got #{inspect(env)}."
1715+
)
1716+
end
1717+
17061718
:ok
17071719
end
17081720

apps/language_server/lib/language_server/server.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,19 @@ defmodule ElixirLS.LanguageServer.Server do
16401640
prev_env = state.settings["envVariables"]
16411641

16421642
if is_nil(prev_env) or env == prev_env do
1643-
System.put_env(env)
1643+
try do
1644+
System.put_env(env)
1645+
rescue
1646+
e ->
1647+
Logger.error(
1648+
"Cannot set environment variables to #{inspect(env)}: #{Exception.message(e)}"
1649+
)
1650+
1651+
JsonRpc.show_message(
1652+
:error,
1653+
"Invalid `envVariables` in configuration. Expected a map with string key value pairs, got #{inspect(env)}."
1654+
)
1655+
end
16441656
else
16451657
JsonRpc.show_message(
16461658
:warning,

0 commit comments

Comments
 (0)