ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
803 stars 54 forks source link

TypeError: Can't convert 'list' object to str implicitly #122

Closed jt-wang closed 8 years ago

jt-wang commented 8 years ago

I am now stuck at this error written in the title and google everywhere but failt to find any solution or working around.

I follow the instructions step by step,

  1. After installing according to the README.md of this repo, firstly I got error like this
Traceback (most recent call last):
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 137, in <lambda>
    sublime.set_timeout_async(lambda: maybe_save_pfile(pfile, view, now), 5000)
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 145, in maybe_save_pfile
    send_buffer(pfile, view)
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 338, in send_buffer
    port = server_port(pfile.project)[0]
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 160, in server_port
    started = start_server(project)
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 174, in start_server
    stderr=subprocess.STDOUT, shell=windows)
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1448, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: 'node'
  1. I found some issues discussing on this and add this line to my Tern.sublime-settings -- User.
{
    "tern_command":["node", "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/node_modules/tern/bin/tern", "--no-port-file"] 
}
  1. Okay, the FileNotFoundError seems solved but the TypeError: Can't convert 'list' object to str implicitly stands there and I can not get rid of it. I found an issue on this but that doesn't implies anything for solution.
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 346, in on_deactivated_async
    callback.on_deactivated_async(v)
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 43, in on_deactivated_async
    on_deactivated(view)
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 28, in on_deactivated
    send_buffer(pfile, view)
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 338, in send_buffer
    port = server_port(pfile.project)[0]
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 160, in server_port
    started = start_server(project)
  File "/Users/jtwang/Library/Application Support/Sublime Text 3/Packages/tern_for_sublime/tern.py", line 172, in start_server
    proc = subprocess.Popen(tern_command + tern_arguments, cwd=project.dir, env=env,
TypeError: Can't convert 'list' object to str implicitly

Many thanks.

marijnh commented 8 years ago

That line applies + to two values, tern_command and tern_arguments. Both are read from the options and default to an array. Your settings also seem to set tern_command to an array. Yet the error message suggests that one of them ends up as a string. I can't really explain that.

jt-wang commented 8 years ago

@marijnh Thank you for your quick reply! I don't know why but just manage to get it right...after add a .tern-project file in my directory. It does help.

{
  "plugins": {
    "node": {}
  }
}

However, sometimes I cannot get useful autocomplete for nodejs.

Tern can jump to definition and describe the module with require(), which I think means tern works without error. Nevertheless, autocomplete fails time to time and sometimes it even causes timed out popup. Do you think it is a bug or it is because the program of tern takes time to run and analyse the file?

marijnh commented 8 years ago

Some type of code or dependency graphs do unfortunately still make Tern very slow. It tries to automatically cut off analysis in such a case but that system isn't terribly robust yet.

marijnh commented 8 years ago

I have no idea how adding .tern-project could have solves the issue you described, but I guess it went away, so I'm closing this.