Permalink
Browse files

Avoid stack trace on missing XML root node, #25.

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...
1 parent ad06106 commit 2b7d0061e5b7c7a53a49e3d73b0af2397d991af6 @zenhob zenhob committed Aug 4, 2009
Showing with 20 additions and 11 deletions.
  1. +16 −11 lib/hcl.rb
  2. +2 −0 lib/hcl/day_entry.rb
  3. +2 −0 lib/hcl/timesheet_resource.rb
View
@@ -39,21 +39,26 @@ def self.command *args
end
def run
- if @command
- if respond_to? @command
- result = send @command, *@args
- if not result.nil?
- if result.respond_to? :to_a
- puts result.to_a.join(', ')
- elsif result.respond_to? :to_s
- puts result
+ begin
+ if @command
+ if respond_to? @command
+ result = send @command, *@args
+ if not result.nil?
+ if result.respond_to? :to_a
+ puts result.to_a.join(', ')
+ elsif result.respond_to? :to_s
+ puts result
+ end
end
+ else
+ raise UnknownCommand, "unrecognized command `#{@command}'"
end
else
- raise UnknownCommand, "unrecognized command `#{@command}'"
+ show
end
- else
- show
+ rescue TimesheetResource::Failure => e
+ puts "Internal failure. #{e}"
+ exit 1
end
end
View
@@ -2,6 +2,7 @@
class HCl
class DayEntry < TimesheetResource
include Utility
+
# Get the time sheet entries for a given day. If no date is provided
# defaults to today.
def self.all date = nil
@@ -15,6 +16,7 @@ def to_s
def self.from_xml xml
doc = REXML::Document.new xml
+ raise Failure, "No root node in XML document: #{xml}" if doc.root.nil?
Task.cache_tasks doc
doc.root.elements.collect('//day_entry') do |day|
new xml_to_hash(day)
@@ -1,5 +1,7 @@
class HCl
class TimesheetResource
+ class Failure < Exception; end
+
def self.configure opts = nil
if opts
self.login = opts['login']

0 comments on commit 2b7d006

Please sign in to comment.