1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 14:52:19 +03:00

Add connection error handling for NvimApi usage

This commit is contained in:
Tae Won Ha 2017-12-14 22:13:50 +01:00
parent 040777594f
commit 89393e4da3
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 12 additions and 3 deletions

View File

@ -89,7 +89,7 @@ static void socket_call_back(
if ((_native_socket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
NSLog(@"Error: Unix domain socket NULL!");
return [NSError errorWithDomain:NSPOSIXErrorDomain code:-1 userInfo:@{
NSLocalizedDescriptionKey: @"Unix domain socket is NULL.",
NSLocalizedDescriptionKey: @"Could not create unix domain socket.",
}];
}
@ -134,7 +134,7 @@ static void socket_call_back(
}
- (void)disconnectAndStop {
if (CFSocketIsValid(_socket)) {
if (_socket != NULL && CFSocketIsValid(_socket)) {
CFRunLoopStop(_run_loop);
CFSocketInvalidate(_socket);
[_thread cancel];

View File

@ -4,6 +4,7 @@
*/
import Cocoa
import NvimMsgPack
extension NvimView {
@ -57,7 +58,14 @@ extension NvimView {
self.logger.info("=== Starting neovim...")
let noErrorDuringInitialization = self.uiClient.runLocalServerAndNeoVim(withWidth: size.width, height: size.height)
try? self.nvim.connect()
do {
try self.nvim.connect()
} catch {
logger.fault("Could not connect to nvim: \(error)")
self.nvim.disconnect()
self.ipcBecameInvalid(String(describing: error))
return
}
if noErrorDuringInitialization == false {
self.logger.fault("There was an error launching neovim.")

View File

@ -218,6 +218,7 @@ extension NvimView {
self.delegate?.ipcBecameInvalid(reason: reason)
self.bridgeLogger.error("Force-closing due to IPC error.")
self.nvim.disconnect()
self.uiClient.forceQuit()
}
}