emacsorphanage / dart-mode

An Emacs mode for the Dart language
GNU General Public License v3.0
15 stars 2 forks source link

Analysis server error: Invalid file path format: d:/Home/development/dart #68

Closed hello-code closed 5 years ago

hello-code commented 6 years ago

Environment: Windows 7 64bit Emacs 26.1

dart --version
Dart VM version: 2.0.0 (Fri Aug 3 10:53:23 2018 +0200) on "windows_x64"

When I open a dart file, emacs show this message: error in process filter: Analysis server error: Invalid file path format: d:/Home/development/dart

dart-debug:

2018-09-17T15:52:51+0800
Sent: {"id":"1","method":"analysis.setAnalysisRoots","params":{"included":["d:/Home/development/dart"],"excluded":null}}

2018-09-17T15:52:51+0800
Sent: {"id":"2","method":"analysis.setAnalysisRoots","params":{"included":["d:/Home/development/dart"],"excluded":null}}

2018-09-17T15:52:52+0800
Received: {"event":"server.connected","params":{"version":"1.20.3","pid":1580,"sessionId":""}}

2018-09-17T15:52:52+0800
Received: {"id":"1","error":{"code":"INVALID_FILE_PATH_FORMAT","message":"Invalid file path format: d:/Home/development/dart"}}

my dart config:

(use-package dart-mode
  :ensure t
  :config
  (setq dart-debug t)
  (setq  
   dart-analysis-server-snapshot-path "C:/Program Files/Dart/dart-sdk/bin/snapshots/analysis_server.dart.snapshot"
   dart-enable-analysis-server t
   )
  )
bradyt commented 5 years ago

@hello-code Can you also check with (setq debug-on-error t) and share the backtrace? Can you reproduce this without working on two separate drives? Can you reproduce this in a docker instance? I've shared an example docker setup in the wiki. Do you have dart plugins setup in other editors? I wonder if this is actually an issue with dart, not dart-mode. Potentially we may want to submit this at https://github.com/dart-lang/sdk/issues.

Perhaps there is something unusual about that location in d:/ drive? Are there any symlinks involved? Is the capitalization of the path correct? Reading about INVALID_FILE_PATH_FORMAT at https://htmlpreview.github.io/?https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/doc/api.html, I see

The format of the given file path is invalid, e.g. is not absolute and normalized.

Also, dart-analysis-server-snapshot-path has been removed from the project.

Closed until issue is clarified.

JosePtm2 commented 5 years ago

I'm getting the same error,

dart--analysis-server-on-error-callback: Analysis server error: Invalid file path format: c:/Users/USER/Desktop

From the dart-debug:


2018-12-09T10:28:14+0000
Checking syntax for foo.dart

2018-12-09T10:28:14+0000
Sent: {"id":"29","method":"analysis.getErrors","params":{"file":"c:/Users/USER/Desktop/foo.dart"}}

2018-12-09T10:28:14+0000
Received: {"id":"28","error":{"code":"INVALID_FILE_PATH_FORMAT","message":"Invalid file path format: c:/Users/USER/Desktop"}}

from the emacs debugger:

Debugger entered--Lisp error: (wrong-type-argument listp #f(compiled-function (event subscription) #<bytecode 0x1001add15>))
  dart--analysis-server-unsubscribe(#f(compiled-function (event subscription) #<bytecode 0x1001add15>))
  dart-expand()
  funcall-interactively(dart-expand)
  call-interactively(dart-expand nil nil)
  command-execute(dart-expand)

My init.el:


(require 'cl)
(require 'dart-mode)
(setq dart-debug t)
(setq dart-enable-analysis-server t)
(add-to-list 'auto-mode-alist '("\\.dart\\'" . dart-mode))
(add-hook 'dart-mode-hook 'dart-file-handle)
(add-hook 'dart-mode-hook 'flycheck-mode)
(setq dart-sdk-path "C:/Program Files/Dart/dart-sdk/")

I've reproduced it working on the same drive, and the capitalization of the PATH is correct. I don't have dart-plugins in any other editor.

I don't know how to reproduce this in a docker instance, but i'll try that.

thanks

bradyt commented 5 years ago

Thank you @JosePtm2. I'm reproducing errors in Windows.

Config is

(setq inhibit-startup-screen t)

(require 'package)
(setq package-archives
      '(("gnu" . "https://elpa.gnu.org/packages/")
        ("melpa" . "https://melpa.org/packages/")))
(package-initialize)

(unless (package-installed-p 'dart-mode)
  (package-refresh-contents)
  (package-install 'dart-mode))

(setq dart-enable-analysis-server t)

(setq dart-debug t)
(toggle-debug-on-error)

(find-file "C:/Users/Administrator/Downloads/main.dart")

On starting emacs, I get the following backtrace:

Debugger entered--Lisp error: (error "Analysis server error: Invalid file path format: c:/Users/Administrator/Downloads")
  signal(error ("Analysis server error: Invalid file path format: c:/Users/Administrator/Downloads"))
  error("Analysis server error: %s" "Invalid file path format: c:/Users/Administrator/Downloads")
  (progn (error "Analysis server error: %s" (assoc-default 'message resp-err)))
  (if resp-err (progn (error "Analysis server error: %s" (assoc-default 'message resp-err))))
  (let ((resp-err (assoc-default 'error response))) (if resp-err (progn (error "Analysis server error: %s" (assoc-default 'message resp-err)))))
  dart--analysis-server-on-error-callback(((id . "1") (error (code . "INVALID_FILE_PATH_FORMAT") (message . "Invalid file path format: c:/Users/Administrator/Downloads"))))
  funcall(dart--analysis-server-on-error-callback ((id . "1") (error (code . "INVALID_FILE_PATH_FORMAT") (message . "Invalid file path format: c:/Users/Administrator/Downloads"))))
  (progn (setq dart--analysis-server-callbacks (assq-delete-all id dart--analysis-server-callbacks)) (funcall resp-closure msg))
  (if resp-closure (progn (setq dart--analysis-server-callbacks (assq-delete-all id dart--analysis-server-callbacks)) (funcall resp-closure msg)) (let ((err (dart--get msg 'error))) (if err (dart--analysis-server-on-error-callback msg) (dart-info (format "No callback was associated with id %s" raw-id)))))
  (let ((resp-closure (dart--get dart--analysis-server-callbacks id))) (if resp-closure (progn (setq dart--analysis-server-callbacks (assq-delete-all id dart--analysis-server-callbacks)) (funcall resp-closure msg)) (let ((err (dart--get msg 'error))) (if err (dart--analysis-server-on-error-callback msg) (dart-info (format "No callback was associated with id %s" raw-id))))))
  (if id (let ((resp-closure (dart--get dart--analysis-server-callbacks id))) (if resp-closure (progn (setq dart--analysis-server-callbacks (assq-delete-all id dart--analysis-server-callbacks)) (funcall resp-closure msg)) (let ((err (dart--get msg 'error))) (if err (dart--analysis-server-on-error-callback msg) (dart-info (format "No callback was associated with id %s" raw-id)))))) (let ((event (dart--get msg 'event))) (if event (let ((params (dart--get msg 'params))) (if params (let ((callbacks (dart--get dart--analysis-server-subscriptions event))) (if callbacks (progn (let ((--dolist-tail-- callbacks)) (while --dolist-tail-- (let ((callback (car --dolist-tail--))) (let* ((subscription (cons event callback))) (funcall callback params subscription)) (setq --dolist-tail-- (cdr --dolist-tail--)))))))))))))
  (let ((id (string-to-number raw-id))) (if id (let ((resp-closure (dart--get dart--analysis-server-callbacks id))) (if resp-closure (progn (setq dart--analysis-server-callbacks (assq-delete-all id dart--analysis-server-callbacks)) (funcall resp-closure msg)) (let ((err (dart--get msg 'error))) (if err (dart--analysis-server-on-error-callback msg) (dart-info (format "No callback was associated with id %s" raw-id)))))) (let ((event (dart--get msg 'event))) (if event (let ((params (dart--get msg 'params))) (if params (let ((callbacks (dart--get dart--analysis-server-subscriptions event))) (if callbacks (progn (let ((--dolist-tail-- callbacks)) (while --dolist-tail-- (let ((callback (car --dolist-tail--))) (let* ((subscription (cons event callback))) (funcall callback params subscription)) (setq --dolist-tail-- (cdr --dolist-tail--))))))))))))))
  (if raw-id (let ((id (string-to-number raw-id))) (if id (let ((resp-closure (dart--get dart--analysis-server-callbacks id))) (if resp-closure (progn (setq dart--analysis-server-callbacks (assq-delete-all id dart--analysis-server-callbacks)) (funcall resp-closure msg)) (let ((err (dart--get msg 'error))) (if err (dart--analysis-server-on-error-callback msg) (dart-info (format "No callback was associated with id %s" raw-id)))))) (let ((event (dart--get msg 'event))) (if event (let ((params (dart--get msg 'params))) (if params (let ((callbacks (dart--get dart--analysis-server-subscriptions event))) (if callbacks (progn (let ((--dolist-tail-- callbacks)) (while --dolist-tail-- (let ((callback (car --dolist-tail--))) (let* ((subscription (cons event callback))) (funcall callback params subscription)) (setq --dolist-tail-- (cdr --dolist-tail--)))))))))))))) (let ((event (dart--get msg 'event))) (if event (let ((params (dart--get msg 'params))) (if params (let ((callbacks (dart--get dart--analysis-server-subscriptions event))) (if callbacks (progn (let ((--dolist-tail-- callbacks)) (while --dolist-tail-- (let ((callback (car --dolist-tail--))) (let* ((subscription (cons event callback))) (funcall callback params subscription)) (setq --dolist-tail-- (cdr --dolist-tail--)))))))))))))
  (let ((raw-id (dart--get msg 'id))) (if raw-id (let ((id (string-to-number raw-id))) (if id (let ((resp-closure (dart--get dart--analysis-server-callbacks id))) (if resp-closure (progn (setq dart--analysis-server-callbacks (assq-delete-all id dart--analysis-server-callbacks)) (funcall resp-closure msg)) (let ((err (dart--get msg 'error))) (if err (dart--analysis-server-on-error-callback msg) (dart-info (format "No callback was associated with id %s" raw-id)))))) (let ((event (dart--get msg 'event))) (if event (let ((params (dart--get msg 'params))) (if params (let ((callbacks (dart--get dart--analysis-server-subscriptions event))) (if callbacks (progn (let ((--dolist-tail-- callbacks)) (while --dolist-tail-- (let ((callback (car --dolist-tail--))) (let* ((subscription (cons event callback))) (funcall callback params subscription)) (setq --dolist-tail-- (cdr --dolist-tail--)))))))))))))) (let ((event (dart--get msg 'event))) (if event (let ((params (dart--get msg 'params))) (if params (let ((callbacks (dart--get dart--analysis-server-subscriptions event))) (if callbacks (progn (let ((--dolist-tail-- callbacks)) (while --dolist-tail-- (let ((callback (car --dolist-tail--))) (let* ((subscription (cons event callback))) (funcall callback params subscription)) (setq --dolist-tail-- (cdr --dolist-tail--))))))))))))))
  dart--analysis-server-handle-msg(((id . "1") (error (code . "INVALID_FILE_PATH_FORMAT") (message . "Invalid file path format: c:/Users/Administrator/Downloads"))))
  (let ((message (car --dolist-tail--))) (dart-info (concat "Received: " message)) (dart--analysis-server-handle-msg (let* ((json-array-type 'list)) (json-read-from-string message))) (setq --dolist-tail-- (cdr --dolist-tail--)))
  (while --dolist-tail-- (let ((message (car --dolist-tail--))) (dart-info (concat "Received: " message)) (dart--analysis-server-handle-msg (let* ((json-array-type 'list)) (json-read-from-string message))) (setq --dolist-tail-- (cdr --dolist-tail--))))
  (let ((--dolist-tail-- messages)) (while --dolist-tail-- (let ((message (car --dolist-tail--))) (dart-info (concat "Received: " message)) (dart--analysis-server-handle-msg (let* ((json-array-type 'list)) (json-read-from-string message))) (setq --dolist-tail-- (cdr --dolist-tail--)))))
  (let* ((messages (let (result) (let ((list (-butlast buf-lines)) (it-index 0)) (while list (let ((it (car list))) (if (and it (not (string-empty-p it))) (progn (setq result (cons it result))))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (nreverse result)))) (let ((--dolist-tail-- messages)) (while --dolist-tail-- (let ((message (car --dolist-tail--))) (dart-info (concat "Received: " message)) (dart--analysis-server-handle-msg (let* ((json-array-type 'list)) (json-read-from-string message))) (setq --dolist-tail-- (cdr --dolist-tail--))))))
  (let* ((buf-lines (s-lines (buffer-string)))) (delete-region (point-min) (point-max)) (insert (-last-item buf-lines)) (let* ((messages (let (result) (let ((list (-butlast buf-lines)) (it-index 0)) (while list (let ((it (car list))) (if (and it (not (string-empty-p it))) (progn (setq result (cons it result))))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (nreverse result)))) (let ((--dolist-tail-- messages)) (while --dolist-tail-- (let ((message (car --dolist-tail--))) (dart-info (concat "Received: " message)) (dart--analysis-server-handle-msg (let* ((json-array-type 'list)) (json-read-from-string message))) (setq --dolist-tail-- (cdr --dolist-tail--)))))))
  (save-current-buffer (set-buffer buf) (goto-char (point-max)) (insert string) (let* ((buf-lines (s-lines (buffer-string)))) (delete-region (point-min) (point-max)) (insert (-last-item buf-lines)) (let* ((messages (let (result) (let ((list (-butlast buf-lines)) (it-index 0)) (while list (let ((it (car list))) (if (and it (not (string-empty-p it))) (progn (setq result (cons it result))))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (nreverse result)))) (let ((--dolist-tail-- messages)) (while --dolist-tail-- (let ((message (car --dolist-tail--))) (dart-info (concat "Received: " message)) (dart--analysis-server-handle-msg (let* ((json-array-type 'list)) (json-read-from-string message))) (setq --dolist-tail-- (cdr --dolist-tail--))))))))
  (let* ((buf (progn (or (and (memq (type-of das) cl-struct-dart--analysis-server-tags) t) (signal 'wrong-type-argument (list 'dart--analysis-server das))) (aref das 2)))) (if (buffer-live-p buf) nil (throw '--cl-block-dart--analysis-server-process-filter-- nil)) (save-current-buffer (set-buffer buf) (goto-char (point-max)) (insert string) (let* ((buf-lines (s-lines (buffer-string)))) (delete-region (point-min) (point-max)) (insert (-last-item buf-lines)) (let* ((messages (let (result) (let ((list (-butlast buf-lines)) (it-index 0)) (while list (let ((it (car list))) (if (and it (not (string-empty-p it))) (progn (setq result (cons it result))))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (nreverse result)))) (let ((--dolist-tail-- messages)) (while --dolist-tail-- (let ((message (car --dolist-tail--))) (dart-info (concat "Received: " message)) (dart--analysis-server-handle-msg (let* ((json-array-type 'list)) (json-read-from-string message))) (setq --dolist-tail-- (cdr --dolist-tail--)))))))))
  (catch '--cl-block-dart--analysis-server-process-filter-- (let* ((buf (progn (or (and (memq (type-of das) cl-struct-dart--analysis-server-tags) t) (signal 'wrong-type-argument (list 'dart--analysis-server das))) (aref das 2)))) (if (buffer-live-p buf) nil (throw '--cl-block-dart--analysis-server-process-filter-- nil)) (save-current-buffer (set-buffer buf) (goto-char (point-max)) (insert string) (let* ((buf-lines (s-lines (buffer-string)))) (delete-region (point-min) (point-max)) (insert (-last-item buf-lines)) (let* ((messages (let (result) (let ((list (-butlast buf-lines)) (it-index 0)) (while list (let ((it (car list))) (if (and it (not (string-empty-p it))) (progn (setq result (cons it result))))) (setq it-index (1+ it-index)) (setq list (cdr list)))) (nreverse result)))) (let ((--dolist-tail-- messages)) (while --dolist-tail-- (let ((message (car --dolist-tail--))) (dart-info (concat "Received: " message)) (dart--analysis-server-handle-msg (let* ((json-array-type 'list)) (json-read-from-string message))) (setq --dolist-tail-- (cdr --dolist-tail--))))))))))
  dart--analysis-server-process-filter(#s(dart--analysis-server :process #<process dart-analysis-server> :buffer #<buffer dart-analysis-server>) "{\"id\":\"1\",\"error\":{\"code\":\"INVALID_FILE_PATH_FORMAT\",\"message\":\"Invalid file path format: c:/Users/Administrator/Downloads\"}}\n{\"id\":\"2\",\"error\":{\"code\":\"INVALID_FILE_PATH_FORMAT\",\"message\":\"Invalid file path format: c:/Users/Administrator/Downloads\"}}\n")
  (closure ((instance . #s(dart--analysis-server :process #<process dart-analysis-server> :buffer #<buffer dart-analysis-server>)) (process . #<process dart-analysis-server>) cl-struct-dart--analysis-server-tags t) (_ string) (dart--analysis-server-process-filter instance string))(#<process dart-analysis-server> "{\"id\":\"1\",\"error\":{\"code\":\"INVALID_FILE_PATH_FORMAT\",\"message\":\"Invalid file path format: c:/Users/Administrator/Downloads\"}}\n{\"id\":\"2\",\"error\":{\"code\":\"INVALID_FILE_PATH_FORMAT\",\"message\":\"Invalid file path format: c:/Users/Administrator/Downloads\"}}\n")

The contents of *dart-debug* buffer are


2018-12-09T21:23:03+0000
Sent: {"id":"1","method":"analysis.setAnalysisRoots","params":{"included":["c:/Users/Administrator/Downloads"],"excluded":null}}

2018-12-09T21:23:03+0000
Sent: {"id":"2","method":"analysis.setAnalysisRoots","params":{"included":["c:/Users/Administrator/Downloads"],"excluded":null}}

2018-12-09T21:23:12+0000
Received: {"event":"server.connected","params":{"version":"1.21.1","pid":1904,"sessionId":""}}

2018-12-09T21:23:12+0000
Received: {"id":"1","error":{"code":"INVALID_FILE_PATH_FORMAT","message":"Invalid file path format: c:/Users/Administrator/Downloads"}}
bradyt commented 5 years ago

These issues look related:

JosePtm2 commented 5 years ago

So assuming that the problem resides in the Drive Letter casing in the path, how should i capitalize it? I've tried to directly set the var in the dart-mode.el file with (set 'buffer-file-name), but the server response keeps

2018-12-09T23:27:14+0000
Sent: {"id":"8","method":"analysis.updateContent","params":{"files":{"e:/Projects/Flutter/foo_proj/lib/main.dart":{"type":"change","edits":[{"offset":61,"length":0,"replacement":"c"}]}}}}
bradyt commented 5 years ago

@JosePtm2 I think I fixed the invalid file path format in master, it was the forward slashes that dart-mode.el had in building paths. The casing of drive letters seems to be fine.

I've found a couple new issues in Windows dart-mode related to dartfmt, should have them fixed in a few more new issues and commits soon.

If invalid file path format is fixed for you on master (in particular, by commit https://github.com/bradyt/dart-mode/commit/9db2679f1d933377c0d45c01e37721e6f45813f1), please close this issue.

JosePtm2 commented 5 years ago

Ok. so the problem persists.

I get this message when the server starts

2018-12-10T10:24:01+0000
Sent: {"id":"1","method":"analysis.setAnalysisRoots","params":{"included":["e:\\Projects\\Flutter\\foo_app"],"excluded":null}}

2018-12-10T10:24:01+0000
Sent: {"id":"2","method":"analysis.setAnalysisRoots","params":{"included":["e:\\Projects\\Flutter\\foo_app"],"excluded":null}}

2018-12-10T10:24:01+0000
Checking syntax for main.dart

This shows that the file path is correct when its added to the Analysis root, but then when it tries to use the analysis methods, the path is wrong again.

2018-12-10T10:24:01+0000
Sent: {"id":"3","method":"analysis.getErrors","params":{"file":"e:/Projects/Flutter/foo_app/lib/main.dart"}}

2018-12-10T10:24:02+0000
Received: {"event":"server.connected","params":{"version":"1.21.1","pid":20300,"sessionId":""}}

2018-12-10T10:24:02+0000
Received: {"event":"analysis.errors","params":{"file":"e:\\Projects\\Flutter\\foo_app\\pubspec.yaml","errors":[]}}

2018-12-10T10:24:02+0000
Received: {"id":"1"}

2018-12-10T10:24:02+0000
Received: {"id":"2"}

2018-12-10T10:24:02+0000
Received: {"id":"3","error":{"code":"GET_ERRORS_INVALID_FILE","message":"Error during `analysis.getErrors`: invalid file."}}

2018-12-10T10:24:02+0000
Reporting to flycheck: ((id . 3) (error (code . GET_ERRORS_INVALID_FILE) (message . Error during `analysis.getErrors`: invalid file.)))

2018-12-10T10:24:02+0000
Parsed errors: nil

Could this be because it's using the buffer-file-name, which translates to "e:/Projects/Flutter/foo_app/lib/main.dart"?

I got the dartfmt to work simply by changing its name to dartfmt.exe in the previous version. with this new version i just had to change it back and it works as expected.