Skip to content

Commit

Permalink
validate string before parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Nov 17, 2023
1 parent 22de3f6 commit 3ad9449
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/elixir_sense/core/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ defmodule ElixirSense.Core.Parser do
def parse_file(file, try_to_fix_parse_error, try_to_fix_line_not_found, cursor_line_number) do
case File.read(file) do
{:ok, source} ->
parse_string(
source,
try_to_fix_parse_error,
try_to_fix_line_not_found,
cursor_line_number
)
if String.valid?(source) do
parse_string(
source,
try_to_fix_parse_error,
try_to_fix_line_not_found,
cursor_line_number
)
else
Logger.warning("Invalid encoding in #{file}")
create_metadata("", {:error, :invalid_encoding})
end

error ->
Logger.warning("Unable to read file #{file}: #{inspect(error)}")
Expand Down

0 comments on commit 3ad9449

Please sign in to comment.