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

If idris2 --ide-mode-socket is already running, idris2-run mistakenly tries to connect to port 98 #26

Open
rntz opened this issue Jul 11, 2022 · 1 comment

Comments

@rntz
Copy link

rntz commented Jul 11, 2022

Ubuntu 22.04 LTS
GNU Emacs 27.1
Idris version 0.5.1-68a144bf1

If I already have idris2 --ide-mode-socket running somewhere, running it again produces an error message:

$ idris2 --ide-mode-socket &
38398
$ idris2 --ide-mode-socket
Failed to bind socket with error: 98

If, while I have idris2 --ide-mode-socket running elsewhere, I try idris2-run in Emacs, I see this error:

Warning from Idris2: Failed to bind socket with error: 
error in process filter: open-network-stream: make client process failed: Connection refused, :name, Idris2 IDE support, :buffer, *idris2-connection*, :host, 127.0.0.1, :service, 98, :nowait, nil, :tls-parameters, nil
error in process filter: make client process failed: Connection refused, :name, Idris2 IDE support, :buffer, *idris2-connection*, :host, 127.0.0.1, :service, 98, :nowait, nil, :tls-parameters, nil
Idris2 disconnected: exited abnormally with code 1

This is a bit strange. What seems to be happening is that idris2-process-filter has a bug or misfeature:

(defun idris2-process-filter (string)
  "Accept output from the process"
  (if idris2-connection
      string
    ;; Idris2 sometimes prints a warning prior to the port number, which causes
    ;; `string-match' to return 0
    (cl-flet ((idris2-warn (msg)
                          (unless (or (null msg) (string-blank-p msg))
                            (message "Warning from Idris2: %s" msg))))
      (if (not (string-match idris2-process-port-output-regexp string))
          (idris2-warn string)
        (idris2-warn (match-string 1 string))
        (idris2-connect (string-to-number (match-string 2 string))))
      "")))

Here, string gets bound to "Failed to bind socket with error: 98\n". Then string-match succeeds (returning 0) because there is indeed a number in this string and idris2-process-port-output-regexp is not start-/end-anchored. So we take the second branch, warn about the part of the string before the number, and interpret 98 as a port number. Unfortunately, it isn't.

The simplest way to fix this would be to anchor idris2-process-port-output-regexp (add ^ to beginning and $ to the end). Unfortunately, the way the code is written suggests there's some case where idris2 --ide-mode-socket produces a warning followed by a genuine port number. I'm not sure what this case is, so I don't know the best way to distinguish between that case and this one.

I think I ran into this problem because I had tried loading a file with idris-mode, which had managed to start an idris2 process but had some unrelated problem, so I tried installing idris2-mode and when I tried to load the file with idris2-mode, the old process was still around.

It also seems unfortunate that idris2 --ide-mode-socket fails if a copy is already running, I'll try to report that upstream.

@dunhamsteve
Copy link

This issue should be fixed upstream now. When you get a chance, can you verify with a recent build from the main branch of Idris2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants