mirror of
https://github.com/commaai/msgq.git
synced 2026-06-11 23:44:58 +08:00
connect: add error messages when Socket connect fails (#456)
* Throw runtime_error in Socket::create * Add messages to MessagingError * Fix cython bindings * Write a message to stderr instead of throwing runtime_error
This commit is contained in:
@@ -64,8 +64,10 @@ SubSocket * SubSocket::create(Context * context, std::string endpoint, std::stri
|
||||
if (r == 0) {
|
||||
return s;
|
||||
} else {
|
||||
std::cerr << "Error, failed to connect SubSocket to " << endpoint << ": " << strerror(errno) << std::endl;
|
||||
|
||||
delete s;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +89,10 @@ PubSocket * PubSocket::create(Context * context, std::string endpoint, bool chec
|
||||
if (r == 0) {
|
||||
return s;
|
||||
} else {
|
||||
std::cerr << "Error, failed to bind PubSocket to " << endpoint << ": " << strerror(errno) << std::endl;
|
||||
|
||||
delete s;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from libcpp.string cimport string
|
||||
from libcpp.vector cimport vector
|
||||
from libcpp cimport bool
|
||||
from libc cimport errno
|
||||
from libc.string cimport strerror
|
||||
from cython.operator import dereference
|
||||
|
||||
|
||||
@@ -18,7 +19,10 @@ from .messaging cimport Event as cppEvent, SocketEventHandle as cppSocketEventHa
|
||||
|
||||
|
||||
class MessagingError(Exception):
|
||||
pass
|
||||
def __init__(self, endpoint=None):
|
||||
suffix = "with {endpoint}" if endpoint else ""
|
||||
message = f"Messaging failure {suffix}: {strerror(errno.errno)}"
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class MultiplePublishersError(MessagingError):
|
||||
@@ -184,9 +188,9 @@ cdef class SubSocket:
|
||||
|
||||
if r != 0:
|
||||
if errno.errno == errno.EADDRINUSE:
|
||||
raise MultiplePublishersError
|
||||
raise MultiplePublishersError(endpoint)
|
||||
else:
|
||||
raise MessagingError
|
||||
raise MessagingError(endpoint)
|
||||
|
||||
def setTimeout(self, int timeout):
|
||||
self.socket.setTimeout(timeout)
|
||||
@@ -225,9 +229,9 @@ cdef class PubSocket:
|
||||
|
||||
if r != 0:
|
||||
if errno.errno == errno.EADDRINUSE:
|
||||
raise MultiplePublishersError
|
||||
raise MultiplePublishersError(endpoint)
|
||||
else:
|
||||
raise MessagingError
|
||||
raise MessagingError(endpoint)
|
||||
|
||||
def send(self, bytes data):
|
||||
length = len(data)
|
||||
|
||||
Reference in New Issue
Block a user