summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorZack Hobson2009-08-03 19:07:05 -0700
committerZack Hobson2009-08-03 19:07:17 -0700
commit2b7d0061e5b7c7a53a49e3d73b0af2397d991af6 (patch)
tree5209044d7fcff7b87c6f409e5ffc280b31d2801d /lib
parentad061068a2d2a7a26e0f34797d8d977e5594bd3c (diff)
downloadhcl-2b7d0061e5b7c7a53a49e3d73b0af2397d991af6.tar.bz2
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/hcl.rb27
-rw-r--r--lib/hcl/day_entry.rb2
-rw-r--r--lib/hcl/timesheet_resource.rb2
3 files changed, 20 insertions, 11 deletions
diff --git a/lib/hcl.rb b/lib/hcl.rb
index f5889ab..e045328 100644
--- a/lib/hcl.rb
+++ b/lib/hcl.rb
@@ -39,21 +39,26 @@ class HCl
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
diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb
index 9948250..874273f 100644
--- a/lib/hcl/day_entry.rb
+++ b/lib/hcl/day_entry.rb
@@ -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 @@ class HCl
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)
diff --git a/lib/hcl/timesheet_resource.rb b/lib/hcl/timesheet_resource.rb
index 381fe53..3072d07 100644
--- a/lib/hcl/timesheet_resource.rb
+++ b/lib/hcl/timesheet_resource.rb
@@ -1,5 +1,7 @@
class HCl
class TimesheetResource
+ class Failure < Exception; end
+
def self.configure opts = nil
if opts
self.login = opts['login']