From 37dc649fd73d46616a71b8dcb6ebc49310d627a2 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 11 Aug 2017 10:20:03 +0200 Subject: [PATCH] F #5305: Improve error handling --- src/onedb/fsck.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/onedb/fsck.rb b/src/onedb/fsck.rb index 06aba4298e..707d723707 100644 --- a/src/onedb/fsck.rb +++ b/src/onedb/fsck.rb @@ -575,7 +575,13 @@ EOT id = disk.at_xpath("IMAGE_ID") if id - image = get_image_from_id(id.content) + begin + image = get_image_from_id(id.content) + rescue => e + template_id = doc.root.at_xpath("ID").content + STDERR.puts "Error processing template: #{template_id}" + raise e + end else image = get_image_from_name(disk, uid) end @@ -598,7 +604,17 @@ EOT # Params: # +id+:: ID of the image def get_image_from_id(id) - row = @db.fetch("SELECT body from image_pool where oid=#{id}").first + # if IMAGE_ID has a non positive integer (>=0) return nil + return nil if id !~ /^\d+$/ + + begin + sql_cmd = "SELECT body FROM image_pool WHERE oid='#{id}'" + row = @db.fetch(sql_cmd).first + rescue => e + STDERR.puts "Error executing: #{sql_cmd}" + raise e + end + # No image found, so unable to get image TYPE return nil if row.nil?