From 3db1cdd289d4196da2007083f5d517ef4a489dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Fri, 4 Jun 2021 13:24:43 +0200 Subject: [PATCH 1/2] Allow nil message in SystemError.new_from_os_error os_error value may be nil, hence the message can be nil, too --- src/socket/addrinfo.cr | 2 +- src/system_error.cr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/socket/addrinfo.cr b/src/socket/addrinfo.cr index b719ace44b07..9642c70bdb81 100644 --- a/src/socket/addrinfo.cr +++ b/src/socket/addrinfo.cr @@ -96,7 +96,7 @@ class Socket new error_code, nil, domain: domain end - protected def self.new_from_os_error(message : String, os_error, *, domain, type, service, protocol, **opts) + protected def self.new_from_os_error(message : String?, os_error, *, domain, type, service, protocol, **opts) new(message, **opts) end diff --git a/src/system_error.cr b/src/system_error.cr index 41cfe6d63022..e5a6fcf87caf 100644 --- a/src/system_error.cr +++ b/src/system_error.cr @@ -27,7 +27,7 @@ # Prepares the message that goes before the system error description. # By default it returns the original message unchanged. But that could be # customized based on the keyword arguments passed to `from_errno` or `from_winerror`. -# * `protected def new_from_os_error(message : String, os_error, **opts)` +# * `protected def new_from_os_error(message : String?, os_error, **opts)` # Creates an instance of the exception that wraps a system error. # This is a factory method and by default it creates an instance # of the current class. It can be overridden to generate different @@ -103,7 +103,7 @@ module SystemError # This is a factory method and by default it creates an instance # of the current class. It can be overridden to generate different # classes based on the `os_error` value or keyword arguments. - protected def new_from_os_error(message : String, os_error, **opts) + protected def new_from_os_error(message : String?, os_error, **opts) self.new(message, **opts) end From 1ad2aa2110a8e20793d0986891190ccd4e91cb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Fri, 4 Jun 2021 13:25:03 +0200 Subject: [PATCH 2/2] Fix Socket::Connect error in addrinfo inherit os_error --- src/socket/addrinfo.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/socket/addrinfo.cr b/src/socket/addrinfo.cr index 9642c70bdb81..42705a8f7f7a 100644 --- a/src/socket/addrinfo.cr +++ b/src/socket/addrinfo.cr @@ -71,7 +71,7 @@ class Socket unless addrinfo = addrinfo.try(&.next?) if error.is_a?(Socket::ConnectError) - raise Socket::ConnectError.from_errno("Error connecting to '#{domain}:#{service}'") + raise Socket::ConnectError.from_os_error("Error connecting to '#{domain}:#{service}'", error.os_error) else raise error if error end