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

Check type of error message from nvim #190

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions nvr/nvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import sys
import textwrap
import time
import traceback

import psutil
import pynvim
Expand Down Expand Up @@ -62,7 +61,7 @@ def try_attach(self, args, nvr, options, arguments):
self.started_new_process = True
return proceed_after_attach(nvr, options, arguments)
time.sleep(0.2)
print(f'[!] Unable to attach to the new nvim process. Is `{" ".join(args)}` working?')
print(f'[!] Unable to attach to the new nvim process. Is `{" ".join(args)}` working?', file=sys.stderr)
sys.exit(1)

def execute_new_nvim_process(self, silent, nvr, options, arguments):
Expand All @@ -82,7 +81,7 @@ def execute_new_nvim_process(self, silent, nvr, options, arguments):
try:
os.execvpe(args[0], args, os.environ)
except FileNotFoundError:
print(f'[!] Can\'t start new nvim process: `{args[0]}` is not in $PATH.')
print(f'[!] Can\'t start new nvim process: `{args[0]}` is not in $PATH.', file=sys.stderr)
sys.exit(1)

def read_stdin_into_buffer(self, cmd):
Expand Down Expand Up @@ -137,8 +136,11 @@ def execute(self, arguments, cmd='edit', silent=False, wait=False):
else:
self.fnameescaped_command(cmd, fname)
except pynvim.api.nvim.NvimError as e:
if not re.search('E37', e.args[0].decode()):
traceback.print_exc()
message = e.args[0]
if isinstance(message, bytes):
message = message.decode()
if not re.search('E37', message):
print(message, file=sys.stderr)
sys.exit(1)
self.diffthis()

Expand Down Expand Up @@ -487,18 +489,18 @@ def proceed_after_attach(nvr, options, arguments):
options.remote_expr = sys.stdin.read()
try:
result = nvr.server.eval(options.remote_expr)
except:
except Exception:
print(textwrap.dedent(f"""
No valid expression: {options.remote_expr}
Test it in Neovim: :echo eval('...')
If you want to execute a command, use -c or -cc instead.
"""))
if type(result) is bytes:
if isinstance(result, bytes):
print(result.decode())
elif type(result) is list:
print(list(map(lambda x: x.decode() if type(x) is bytes else x, result)))
elif type(result) is dict:
print({ (k.decode() if type(k) is bytes else k): v for (k,v) in result.items() })
elif isinstance(result, list):
print(list(map(lambda x: x.decode() if isinstance(x, bytes) else x, result)))
elif isinstance(result, dict):
print({ (k.decode() if isinstance(k, bytes) else k): v for (k,v) in result.items() })
else:
result = str(result)
if not result.endswith(os.linesep):
Expand Down Expand Up @@ -531,7 +533,7 @@ def proceed_after_attach(nvr, options, arguments):
try:
nvr.server.command('tag ' + options.t)
except nvr.server.error as e:
print(e)
print(e, file=sys.stderr)
sys.exit(1)

if options.q:
Expand Down