From 03bd5b2244f9fa5e8a3de40a3678652d2a26f097 Mon Sep 17 00:00:00 2001 From: Marc Fournier Date: Mon, 22 Oct 2012 12:28:01 +0200 Subject: couchdblookup: improved error handling Individually catch frequent errors and print a meaningful error message in puppet logs. --- lib/puppet/parser/functions/couchdblookup.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/puppet/parser/functions/couchdblookup.rb') diff --git a/lib/puppet/parser/functions/couchdblookup.rb b/lib/puppet/parser/functions/couchdblookup.rb index 132c488..b9067d2 100644 --- a/lib/puppet/parser/functions/couchdblookup.rb +++ b/lib/puppet/parser/functions/couchdblookup.rb @@ -16,8 +16,16 @@ module Puppet::Parser::Functions begin json = JSON.parse(open(URI.parse(url)).read) - rescue OpenURI::HTTPError, JSON::ParserError => error - raise Puppet::ParseError, "couchdblookup(): fetching URL #{url} failed with status #{error.message}" + rescue OpenURI::HTTPError => error + raise Puppet::ParseError, "couchdblookup(): fetching URL #{url} failed with status '#{error.message}'" + rescue Timeout::Error => error + raise Puppet::ParseError, "couchdblookup(): connection to couchdb server timed out: '#{error.message}'" + rescue Errno::ECONNREFUSED => error + raise Puppet::ParseError, "couchdblookup(): connection to couchdb server failed: '#{error.message}'" + rescue JSON::ParserError => error + raise Puppet::ParseError, "couchdblookup(): failed to parse JSON received from couchdb: '#{error.message}'" + rescue StandardError => error + raise Puppet::ParseError, "couchdblookup(): something unexpected happened: '#{error.inspect}'" end result = nil -- cgit v1.2.3