Skip to content

Commit

Permalink
fix: better error message when passing invalid flags
Browse files Browse the repository at this point in the history
Closes #103
  • Loading branch information
mhanberg committed Jul 12, 2023
1 parent b8ccf12 commit da733c0
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/next_ls/lsp_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ defmodule NextLS.LSPSupervisor do

@env Mix.env()

defmodule OptionsError do
@moduledoc false
defexception [:message]

@impl true
def exception(options) do
msg = """
Unknown Options: #{Enum.map_join(options, " ", fn {k, v} -> "#{k} #{v}" end)}
Valid options:
--stdio Starts the server using stdio
--port port-number Starts the server using TCP on the given port
"""

%OptionsError{message: msg}
end
end

def start_link(init_arg) do
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
end
Expand All @@ -14,8 +33,8 @@ defmodule NextLS.LSPSupervisor do
if @env == :test do
:ignore
else
{opts, _} =
OptionParser.parse!(System.argv(),
{opts, _, invalid} =
OptionParser.parse(System.argv(),
strict: [stdio: :boolean, port: :integer]
)

Expand All @@ -29,7 +48,7 @@ defmodule NextLS.LSPSupervisor do
[communication: {GenLSP.Communication.TCP, [port: opts[:port]]}]

true ->
raise "Unknown option"
raise OptionsError, invalid
end

children = [
Expand Down

0 comments on commit da733c0

Please sign in to comment.