]> git.r.bdr.sh - rbdr/lyricli.rb/commitdiff
Fixes to gracefully handle some errors
authorBen Beltran <redacted>
Sat, 6 Oct 2012 08:12:31 +0000 (03:12 -0500)
committerBen Beltran <redacted>
Sat, 6 Oct 2012 08:12:31 +0000 (03:12 -0500)
By this point I'm really tired, I hope something silly didn't
go through.

lib/lyricli/lyricli.rb
lyricli-0.0.1.gem

index d546e54d88187c717b01df6cb634213d3febe6ec..c3e1faecb94dd657a98bf78de7e1fe0b972d9b98 100644 (file)
@@ -22,15 +22,20 @@ module Lyricli
     #
     # @return [String] the found lyrics, or a string indicating none were found
     def get_lyrics
     #
     # @return [String] the found lyrics, or a string indicating none were found
     def get_lyrics
-      set_current_track
-      check_params
+
+      begin
+        set_current_track
+        check_params
+      rescue Exceptions::InvalidLyricsError
+        return "No Artist/Song could be found :("
+      end
 
       engine = LyricsEngine.new(@current_track[:artist], @current_track[:song])
 
       begin
 
       engine = LyricsEngine.new(@current_track[:artist], @current_track[:song])
 
       begin
-        engine.get_lyrics
+        return engine.get_lyrics
       rescue Exceptions::LyricsNotFoundError
       rescue Exceptions::LyricsNotFoundError
-        "Lyrics not found :("
+        return "Lyrics not found :("
       end
     end
 
       end
     end
 
@@ -42,6 +47,7 @@ module Lyricli
 
     # Exits with error when there is an empty field from the current track.
     def check_params
 
     # Exits with error when there is an empty field from the current track.
     def check_params
+      self.exit_with_error unless @current_track
       self.exit_with_error if @current_track[:artist].nil? or @current_track[:artist].empty?
       self.exit_with_error if @current_track[:song].nil? or @current_track[:song].empty?
     end
       self.exit_with_error if @current_track[:artist].nil? or @current_track[:artist].empty?
       self.exit_with_error if @current_track[:song].nil? or @current_track[:song].empty?
     end
index c5bbe76f86a5b82aed30fd7ec80fc9fe6d79a19f..3e1023b9057139861f250055c4c9960a718c1d13 100644 (file)
Binary files a/lyricli-0.0.1.gem and b/lyricli-0.0.1.gem differ