1+ import errno # import here for window's skae...
2+
13cdef str __strerr(int errno):
24 return strerror(errno).decode()
35
@@ -8,19 +10,20 @@ cdef __convert_python_error(int uverr):
810 # Implementation detail: on Unix error codes are the
911 # negated errno (or -errno), while on Windows they
1012 # are defined by libuv to arbitrary negative numbers.
11-
13+
1214 cdef int oserr
15+ cdef object err
16+
1317 if system.PLATFORM_IS_WINDOWS:
14-
15- # Winloop comment: The following approach seems to work for Windows:
16- # translation from uverr, which is a negative number like -4088 or -4071
17- # defined by libuv (as mentioned above), to error numbers obtained via
18- # the Python module errno.
18+
19+ # So Let's try converting them a different way if were using windows.
20+ # Winloop has a smarter technique for showing these errors.
1921 err = getattr (errno, uv.uv_err_name(uverr).decode(), uverr)
2022 return OSError (err, uv.uv_strerror(uverr).decode())
21-
23+
2224 oserr = - uverr
2325
26+
2427 exc = OSError
2528
2629 if uverr in (uv.UV_EACCES, uv.UV_EPERM):
@@ -118,7 +121,20 @@ cdef convert_error(int uverr):
118121
119122 sock_err = __convert_socket_error(uverr)
120123 if sock_err:
121- msg = system.gai_strerror(sock_err).decode(' utf-8' )
122- return socket_gaierror(sock_err, msg)
124+ # Winloop comment: Sometimes libraries will throw in some
125+ # unwanted unicode BS to unravel, to prevent the possibility of this being a threat,
126+ # surrogateescape is utilized
127+ # SEE: https://github.com/Vizonex/Winloop/issues/32
128+ msg = system.gai_strerror(sock_err).decode(' utf-8' , " surrogateescape" )
129+ # Winloop comment: on Windows, cPython has a simpler error
130+ # message than uvlib (via winsock probably) in these two cases:
131+ # EAI_FAMILY [ErrNo 10047] "An address incompatible with the requested protocol was used. "
132+ # EAI_NONAME [ErrNo 10001] "No such host is known. "
133+ # We replace these messages with "getaddrinfo failed"
134+ if sys.platform == ' win32' :
135+ if sock_err in (socket_EAI_FAMILY, socket_EAI_NONAME):
136+ msg = ' getaddrinfo failed'
137+ return socket_gaierror(sock_err, msg)
123138
124139 return __convert_python_error(uverr)
140+
0 commit comments