From da1a02892dd255f81b1878c6893e1d8515741867 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 27 Jun 2016 03:14:57 +0200 Subject: [PATCH] log backtrace for unexpected errors in ConnectionTester --- lib/connection_tester.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/connection_tester.rb b/lib/connection_tester.rb index 0783b3a93..e226d53fa 100644 --- a/lib/connection_tester.rb +++ b/lib/connection_tester.rb @@ -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