diff options
| author | Zack Hobson | 2009-08-03 19:07:05 -0700 | 
|---|---|---|
| committer | Zack Hobson | 2009-08-03 19:07:17 -0700 | 
| commit | 2b7d0061e5b7c7a53a49e3d73b0af2397d991af6 (patch) | |
| tree | 5209044d7fcff7b87c6f409e5ffc280b31d2801d /lib | |
| parent | ad061068a2d2a7a26e0f34797d8d977e5594bd3c (diff) | |
| download | hcl-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.rb | 27 | ||||
| -rw-r--r-- | lib/hcl/day_entry.rb | 2 | ||||
| -rw-r--r-- | lib/hcl/timesheet_resource.rb | 2 | 
3 files changed, 20 insertions, 11 deletions
| @@ -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'] | 
