From: Ben Beltran Date: Sat, 6 Oct 2012 08:12:31 +0000 (-0500) Subject: Fixes to gracefully handle some errors X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli.rb/commitdiff_plain/5d701d44f30948d6d339a8d5806a083bdf76076d?ds=inline Fixes to gracefully handle some errors By this point I'm really tired, I hope something silly didn't go through. --- diff --git a/lib/lyricli/lyricli.rb b/lib/lyricli/lyricli.rb index d546e54..c3e1fae 100644 --- a/lib/lyricli/lyricli.rb +++ b/lib/lyricli/lyricli.rb @@ -22,15 +22,20 @@ module Lyricli # # @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.get_lyrics + return engine.get_lyrics rescue Exceptions::LyricsNotFoundError - "Lyrics not found :(" + return "Lyrics not found :(" end end @@ -42,6 +47,7 @@ module Lyricli # 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 diff --git a/lyricli-0.0.1.gem b/lyricli-0.0.1.gem index c5bbe76..3e1023b 100644 Binary files a/lyricli-0.0.1.gem and b/lyricli-0.0.1.gem differ