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