livebook-dev / livebook

Automate code & data workflows with interactive Elixir notebooks

Home Page:https://livebook.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash on Windows when trying to save file if a nearby filename contains an emoji

nixxquality opened this issue · comments

Environment

  • Elixir & Erlang/OTP versions (elixir --version): Erlang/OTP 26, Elixir 1.16.2
  • Operating system: Windows 10
  • How have you started Livebook (mix phx.server, livebook CLI, Docker, etc): Happens with both released Windows exe and mix phx.server
  • Livebook version (use git rev-parse HEAD if running with mix): cb11b26
  • Browsers that reproduce this bug (the more the merrier): All
  • Include what is logged in the browser console:
[error] GenServer #PID<0.1393.0> terminating
** (UnicodeConversionError) invalid code point 55357
    (elixir 1.16.2) lib/list.ex:1103: List.to_string/1
    (elixir 1.16.2) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.16.2) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.16.2) lib/file.ex:1670: File.ls/1
    (livebook 0.13.0-dev) lib/livebook/file_system/local.ex:50: Livebook.FileSystem.Livebook.FileSystem.Local.list/3
    (livebook 0.13.0-dev) lib/livebook/file_system/file.ex:167: Livebook.FileSystem.File.list/2
    (livebook 0.13.0-dev) lib/livebook_web/live/file_select_component.ex:664: LivebookWeb.FileSelectComponent.get_file_infos/3
    (livebook 0.13.0-dev) lib/livebook_web/live/file_select_component.ex:617: LivebookWeb.FileSelectComponent.update_file_infos/2
    (livebook 0.13.0-dev) lib/livebook_web/live/file_select_component.ex:74: LivebookWeb.FileSelectComponent.update/2
    (phoenix_live_view 0.20.6) lib/phoenix_live_view/utils.ex:498: Phoenix.LiveView.Utils.maybe_call_update!/3
    (elixir 1.16.2) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
    (phoenix_live_view 0.20.6) lib/phoenix_live_view/diff.ex:685: anonymous fn/4 in Phoenix.LiveView.Diff.render_pending_components/6
    (telemetry 1.2.1) c:/Users/Linus/Code/livebook/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
    (phoenix_live_view 0.20.6) lib/phoenix_live_view/diff.ex:680: anonymous fn/4 in Phoenix.LiveView.Diff.render_pending_components/6
    (stdlib 5.0) maps.erl:416: :maps.fold_1/4
    (phoenix_live_view 0.20.6) lib/phoenix_live_view/diff.ex:639: Phoenix.LiveView.Diff.render_pending_components/6
    (phoenix_live_view 0.20.6) lib/phoenix_live_view/diff.ex:143: Phoenix.LiveView.Diff.render/3
    (phoenix_live_view 0.20.6) lib/phoenix_live_view/static.ex:249: Phoenix.LiveView.Static.to_rendered_content_tag/4
    (phoenix_live_view 0.20.6) lib/phoenix_live_view/static.ex:132: Phoenix.LiveView.Static.render/3
    (phoenix_live_view 0.20.6) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
Last message: {:continue, :handle_connection}
State: {%ThousandIsland.Socket{socket: #Port<0.25>, transport_module: ThousandIsland.Transports.TCP, read_timeout: 60000, silent_terminate_on_error: false, span: %ThousandIsland.Telemetry{span_name: :connection, telemetry_span_context: #Reference<0.546146728.560463878.35862>, start_time: 3970266607, start_metadata: %{remote_port: 58260, remote_address: {127, 0, 0, 1}, telemetry_span_context: #Reference<0.546146728.560463878.35862>, parent_telemetry_span_context: #Reference<0.546146728.560463878.32837>}}}, %{opts: %{websocket: [], http_1: [max_header_length: 32768], http_2: [max_header_value_length: 32768]}, plug: {Phoenix.Endpoint.SyncCodeReloadPlug, {LivebookWeb.Endpoint, []}}, handler_module: Bandit.InitialHandler, http_1_enabled: true, http_2_enabled: true, websocket_enabled: true}}

Current behavior

On Windows, if you have a file with an emoji in the filename in your home folder, the application crashes when trying to save your livebook.
Note: This is strictly an upstream issue. See elixir-lang/elixir#10959 and erlang/otp#4779.
The issue is known, but seems to be stalled upstream. I don't know if you want to make a workaround for this or not.

Workaround

Rename or move any files containing emoji in their filenames away from your home directory, or any directories you traverse with the file browser.

An alternative workaround would be to paste a path directly instead of navigating through the problematic directories.

We could catch the error and return [] from ls, that wouldn't exactly fix the navigation (there would be no entries to click), it would just avoid the crash while typing. Given how rare emoji filenames are, I would just wait for the fix in OTP. @josevalim whichever you prefer!

@jonatanklosko we can use this instead:

# Erlang currently chokes on emoji directories on Windows,
# so we discard those.
case :file.list_dir(dir) do
  {:ok, list} ->
    {:ok, for(dir <- list, str = try do IO.chardata_to_string(dir) rescue _ -> nil end, do: str )}
  {:error, error} ->
    {:error, error}
end

So we keep it working on all cases?

@josevalim ah we can filter individual names, sounds good! #2558