hyrious / prettierd

Yet another sublime text prettier plugin.
MIT License
6 stars 0 forks source link

Prettierd does not run: ConnectionRefusedError #3

Open afonsoduarte opened 2 years ago

afonsoduarte commented 2 years ago

I'm running Sublime 4, build 4126 on macOS 12.5, and Prettierd isn't running. As soon as I open Sublime, I see the following in the console:

prettierd: spawning subprocess
prettierd: {"ok":9870}

prettierd: spawn success ok
Traceback (most recent call last):
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/prettierd.py", line 94, in refresh_views
    check_formattable(view)
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/prettierd.py", line 104, in check_formattable
    data = call('getFileInfo', { "path": filename })
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/prettierd.py", line 24, in call
    return tcp_request(server, make_request(*args, seq=seq, **kwargs))
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/lib/utils.py", line 7, in tcp_request
    client.connect(server)
ConnectionRefusedError: [Errno 61] Connection refused

Once I try to save the file, I see 2 more errors in the console:

Traceback (most recent call last):
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/prettierd.py", line 257, in <lambda>
    sublime.set_timeout_async(lambda: check_formattable(view))
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/prettierd.py", line 104, in check_formattable
    data = call('getFileInfo', { "path": filename })
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/prettierd.py", line 24, in call
    return tcp_request(server, make_request(*args, seq=seq, **kwargs))
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/lib/utils.py", line 7, in tcp_request
    client.connect(server)
ConnectionRefusedError: [Errno 61] Connection refused
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python38/sublime_plugin.py", line 924, in on_post_save
    run_view_callbacks('on_post_save', view_id)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python38/sublime_plugin.py", line 728, in run_view_callbacks
    callback(v, *args)
  File "/Applications/Sublime Text.app/Contents/MacOS/Lib/python38/sublime_plugin.py", line 152, in profiler
    return event_handler(*args)
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/prettierd.py", line 253, in on_post_save
    call("clearConfigCache")
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/prettierd.py", line 24, in call
    return tcp_request(server, make_request(*args, seq=seq, **kwargs))
  File "/Users/[REDACTED]/Library/Application Support/Sublime Text/Packages/prettierd/lib/utils.py", line 7, in tcp_request
    client.connect(server)
ConnectionRefusedError: [Errno 61] Connection refused

I have prettier installed globally, and no other prettier plugins installed on Sublime.

Let me know if there's anything else I should post to help track down this issue.

hyrious commented 2 years ago

It seems macOS is preventing Sublime Text.app to create TCP connections on your machine. I don't know macOS very much but it does work on mine. You may goto  > System Preferences > Security & Privacy > … to see if Sublime Text was blocked by some reason.

If for some reason the deamon process was killed, then any further requests will result in Connection Refused error. This is rarely seen (I haven't seen any) but it is still possible. So I just fixed that in c276cfa to try respawn server on any TCP error. You can update your plugin (basically uninstall and install it again) to see if it works.

afonsoduarte commented 2 years ago

I checked Security & Privacy but no trace of Sublime there. I also tried installing prettierd in a brand new Sublime, in a different laptop, and the result was the same.

With this new patch, it gets stuck trying to connect and failing, in a loop.

If I launch the node server manually with node prettierd.mjs 9870, the plugin works as expected. So it seems like the node server is going down as soon as it's spun by the plugin.

hyrious commented 2 years ago

Sorry but I cannot reproduce this problem on my macOS (same version as yours) / Windows (10, latest). The node server seems to be launched successfully on its first run since it outputs {"ok":9870} in your console log above. Here's the corresponding python code that spawns it: https://github.com/hyrious/prettierd/blob/5ddb6b30957649fa6c04cc8371cfc71cdc296d84/prettierd.py#L70-L76

I will mark this as unactionable unless you/me/someone else could figure out how it happens.