log backtrace for unexpected errors in ConnectionTester

This commit is contained in:
Benjamin Neff 2016-06-27 03:14:57 +02:00
parent 28ca071e79
commit da1a02892d

View file

@ -1,7 +1,9 @@
class ConnectionTester class ConnectionTester
NODEINFO_SCHEMA = "http://nodeinfo.diaspora.software/ns/schema/1.0" include Diaspora::Logging
NODEINFO_FRAGMENT = "/.well-known/nodeinfo"
NODEINFO_SCHEMA = "http://nodeinfo.diaspora.software/ns/schema/1.0".freeze
NODEINFO_FRAGMENT = "/.well-known/nodeinfo".freeze
class << self class << self
# Test the reachability of a server by the given HTTP/S URL. # Test the reachability of a server by the given HTTP/S URL.
@ -74,7 +76,7 @@ class ConnectionTester
rescue URI::InvalidURIError => e rescue URI::InvalidURIError => e
raise AddressFailure, e.message raise AddressFailure, e.message
rescue StandardError => e rescue StandardError => e
raise Failure, e.inspect unexpected_error(e)
end end
# Perform the DNS query, the IP address will be stored in the result # Perform the DNS query, the IP address will be stored in the result
@ -84,7 +86,7 @@ class ConnectionTester
rescue SocketError => e rescue SocketError => e
raise DNSFailure, "'#{@uri.host}' - #{e.message}" raise DNSFailure, "'#{@uri.host}' - #{e.message}"
rescue StandardError => e rescue StandardError => e
raise Failure, e.inspect unexpected_error(e)
end end
# Perform a HTTP GET request to determine the following information # Perform a HTTP GET request to determine the following information
@ -113,7 +115,7 @@ class ConnectionTester
rescue ArgumentError, FaradayMiddleware::RedirectLimitReached, Faraday::ClientError => e rescue ArgumentError, FaradayMiddleware::RedirectLimitReached, Faraday::ClientError => e
raise HTTPFailure, e.message raise HTTPFailure, e.message
rescue StandardError => e rescue StandardError => e
raise Failure, e.inspect unexpected_error(e)
end end
# Try to find out the version of the other servers software. # Try to find out the version of the other servers software.
@ -130,7 +132,7 @@ class ConnectionTester
rescue Faraday::ResourceNotFound, JSON::JSONError => e rescue Faraday::ResourceNotFound, JSON::JSONError => e
raise NodeInfoFailure, e.message[0..255].encode(Encoding.default_external, undef: :replace) raise NodeInfoFailure, e.message[0..255].encode(Encoding.default_external, undef: :replace)
rescue StandardError => e rescue StandardError => e
raise Failure, e.inspect unexpected_error(e)
end end
private private
@ -192,6 +194,11 @@ class ConnectionTester
@result.software_version = "#{sw.fetch('name')} #{sw.fetch('version')}" @result.software_version = "#{sw.fetch('name')} #{sw.fetch('version')}"
end end
def unexpected_error(error)
logger.error "unexpected error: #{error.class}: #{error.message}\n#{error.backtrace.first(15).join("\n")}"
raise Failure, error.inspect
end
class Failure < StandardError class Failure < StandardError
end end