Skip to content
This repository has been archived by the owner on Jul 10, 2018. It is now read-only.

Commit

Permalink
Avoid stack trace on missing XML root node, zenhob#25.
Browse files Browse the repository at this point in the history
I've gotten a report of a stack trace. I do not know the cause yet,
but uncaught exceptions are not useful, complaining and showing the
payload might be.
  • Loading branch information
zenhob committed Aug 4, 2009
1 parent ad06106 commit 2b7d006
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/hcl.rb
Expand Up @@ -39,21 +39,26 @@ def self.command *args
end end


def run def run
if @command begin
if respond_to? @command if @command
result = send @command, *@args if respond_to? @command
if not result.nil? result = send @command, *@args
if result.respond_to? :to_a if not result.nil?
puts result.to_a.join(', ') if result.respond_to? :to_a
elsif result.respond_to? :to_s puts result.to_a.join(', ')
puts result elsif result.respond_to? :to_s
puts result
end
end end
else
raise UnknownCommand, "unrecognized command `#{@command}'"
end end
else else
raise UnknownCommand, "unrecognized command `#{@command}'" show
end end
else rescue TimesheetResource::Failure => e
show puts "Internal failure. #{e}"
exit 1
end end
end end


Expand Down
2 changes: 2 additions & 0 deletions lib/hcl/day_entry.rb
Expand Up @@ -2,6 +2,7 @@
class HCl class HCl
class DayEntry < TimesheetResource class DayEntry < TimesheetResource
include Utility include Utility

# Get the time sheet entries for a given day. If no date is provided # Get the time sheet entries for a given day. If no date is provided
# defaults to today. # defaults to today.
def self.all date = nil def self.all date = nil
Expand All @@ -15,6 +16,7 @@ def to_s


def self.from_xml xml def self.from_xml xml
doc = REXML::Document.new xml doc = REXML::Document.new xml
raise Failure, "No root node in XML document: #{xml}" if doc.root.nil?
Task.cache_tasks doc Task.cache_tasks doc
doc.root.elements.collect('//day_entry') do |day| doc.root.elements.collect('//day_entry') do |day|
new xml_to_hash(day) new xml_to_hash(day)
Expand Down
2 changes: 2 additions & 0 deletions lib/hcl/timesheet_resource.rb
@@ -1,5 +1,7 @@
class HCl class HCl
class TimesheetResource class TimesheetResource
class Failure < Exception; end

def self.configure opts = nil def self.configure opts = nil
if opts if opts
self.login = opts['login'] self.login = opts['login']
Expand Down

0 comments on commit 2b7d006

Please sign in to comment.