Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better error message when passing invalid flags #107

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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