Skip to content

Commit 37359e8

Browse files
committed
raise instead of handling invalid or not supported requests
1 parent f074633 commit 37359e8

File tree

1 file changed

+23
-11
lines changed
  • apps/elixir_ls_debugger/lib/debugger

1 file changed

+23
-11
lines changed

apps/elixir_ls_debugger/lib/debugger/server.ex

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -481,17 +481,26 @@ defmodule ElixirLS.Debugger.Server do
481481
defp handle_request(initialize_req(_, client_info), %__MODULE__{client_info: nil} = state) do
482482
# linesStartAt1 is true by default and we only support 1-based indexing
483483
if client_info["linesStartAt1"] == false do
484-
Output.debugger_important("0-based lines are not supported")
484+
raise ServerError,
485+
message: "invalidRequest",
486+
format: "0-based lines are not supported",
487+
variables: %{}
485488
end
486489

487490
# columnsStartAt1 is true by default and we only support 1-based indexing
488491
if client_info["columnsStartAt1"] == false do
489-
Output.debugger_important("0-based columns are not supported")
492+
raise ServerError,
493+
message: "invalidRequest",
494+
format: "0-based columns are not supported",
495+
variables: %{}
490496
end
491497

492498
# pathFormat is `path` by default and we do not support other, e.g. `uri`
493499
if client_info["pathFormat"] not in [nil, "path"] do
494-
Output.debugger_important("pathFormat #{client_info["pathFormat"]} not supported")
500+
raise ServerError,
501+
message: "invalidRequest",
502+
format: "pathFormat {pathFormat} is not supported",
503+
variables: %{"pathFormat" => client_info["pathFormat"]}
495504
end
496505

497506
{capabilities(), %{state | client_info: client_info}}
@@ -1493,10 +1502,14 @@ defmodule ElixirLS.Debugger.Server do
14931502
defp set_stack_trace_mode("all"), do: :int.stack_trace(:all)
14941503
defp set_stack_trace_mode("no_tail"), do: :int.stack_trace(:no_tail)
14951504
defp set_stack_trace_mode("false"), do: :int.stack_trace(false)
1505+
defp set_stack_trace_mode(false), do: :int.stack_trace(false)
14961506
defp set_stack_trace_mode(nil), do: nil
14971507

14981508
defp set_stack_trace_mode(_) do
1499-
Output.debugger_important(~S(stackTraceMode must be "all", "no_tail", or "false"))
1509+
raise ServerError,
1510+
message: "argumentError",
1511+
format: "stackTraceMode must be `all`, `no_tail`, or `false`",
1512+
variables: %{}
15001513
end
15011514

15021515
defp capabilities do
@@ -1607,17 +1620,16 @@ defmodule ElixirLS.Debugger.Server do
16071620

16081621
defp interpret_specified_modules(file_patterns, exclude_module_pattern) do
16091622
regexes =
1610-
Enum.flat_map(file_patterns, fn pattern ->
1623+
Enum.map(file_patterns, fn pattern ->
16111624
case Regex.compile(pattern) do
16121625
{:ok, regex} ->
1613-
[regex]
1626+
regex
16141627

16151628
{:error, error} ->
1616-
Output.debugger_important(
1617-
"Unable to compile file pattern (#{inspect(pattern)}) into a regex. Received error: #{inspect(error)}"
1618-
)
1619-
1620-
[]
1629+
raise ServerError,
1630+
message: "argumentError",
1631+
format: "Unable to compile file pattern {pattern} into a regex: {error}",
1632+
variables: %{"pattern" => inspect(pattern), "error" => inspect(error)}
16211633
end
16221634
end)
16231635

0 commit comments

Comments
 (0)