diff options
author | Marc Fournier <marc.fournier@camptocamp.com> | 2012-10-22 12:28:01 +0200 |
---|---|---|
committer | Marc Fournier <marc.fournier@camptocamp.com> | 2012-10-22 12:28:01 +0200 |
commit | 03bd5b2244f9fa5e8a3de40a3678652d2a26f097 (patch) | |
tree | 7d292054505af595b0a5d58f2510201c4e5cfdd7 | |
parent | e97e408116525f28b53162b89e6b582fb71020d2 (diff) |
couchdblookup: improved error handling
Individually catch frequent errors and print a meaningful error message
in puppet logs.
-rw-r--r-- | lib/puppet/parser/functions/couchdblookup.rb | 12 |
1 files changed, 10 insertions, 2 deletions
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 |