Permalink
Browse files

removed all of this Gsm::Error.desc sillyness

  • Loading branch information...
1 parent 288545c commit 91e63099bdd7f302adbf8717061c9ea2cbfb9b99 @adammck committed Apr 23, 2009
Showing with 20 additions and 23 deletions.
  1. +3 −3 bin/gsm-modem-band
  2. +1 −1 bin/sms
  3. +5 −5 lib/rubygsm/core.rb
  4. +11 −14 lib/rubygsm/errors.rb
View
@@ -12,7 +12,7 @@ begin
rescue Gsm::Modem::Error => err
puts "Initialization Error:"
- puts " " + err.desc
+ puts " #{err}"
exit
end
@@ -38,11 +38,11 @@ if ARGV[0]
begin
modem.band = new_band
puts "Switched to: "
- puts " " + modem.band
+ puts " #{modem.band}"
rescue StandardError => err
puts "Error switching band: "
- puts " " + err
+ puts " #{err}"
end
puts
View
@@ -34,5 +34,5 @@ begin
modem.send_sms!(recipient, msg)
rescue Gsm::Error => err
- puts "Error: #{err.desc}"
+ puts "Error: #{err}"
end
View
@@ -299,7 +299,8 @@ def command(cmd, *args)
out = command!(cmd, *args)
rescue Exception => err
- log_then_decr "Rescued (in #command): #{err.desc}"
+ log_then_decr "Rescued (in #command): #{err}"
+
if (tries += 1) <= @retry_commands
sleep((2**tries)/2)
retry
@@ -362,7 +363,7 @@ def command!(cmd, resp_term=nil, write_term="\r")
# then automatically re-try the command after
# a short delay. for others, propagate
rescue Error => err
- log_then_decr "Rescued (in #command!): #{err.desc}"
+ log_then_decr "Rescued (in #command!): #{err}"
if (err.type == "CMS") and (err.code == 515)
sleep 2
@@ -387,7 +388,7 @@ def try_command(cmd, *args)
return out
rescue Error => err
- log_then_decr "Rescued (in #try_command): #{err.desc}"
+ log_then_decr "Rescued (in #try_command): #{err}"
return nil
end
end
@@ -805,8 +806,7 @@ def send_sms!(*args)
# of AT commands via sms!) so send
# an escpae, to... escape
rescue Exception, Timeout::Error => err
- err_str = err.respond_to?(:desc) ? err.desc : err
- log "Rescued #{err_str}"
+ log "Rescued #{err}"
write 27.chr
if (tries +=1) < @retry_commands
View
@@ -84,7 +84,7 @@ def initialize(type=nil, code=nil)
@type = type
end
- def desc
+ def to_s
# attempt to return something useful
return(ERRORS[@type][@code])\
if(@type and ERRORS[@type] and @code and ERRORS[@type][@code])
@@ -93,39 +93,36 @@ def desc
return "Unknown error (unrecognized command?) " +\
"[type=#{@type}] [code=#{code}]"
end
-
- # not the same as alias :to_s, :desc,
- # because this works on subclasses
- def to_s
- desc
- end
end
- # TODO: what the hell is going on with
- # all these "desc" methods? refactor this
-
class TimeoutError < Error #:nodoc:
- def desc
+ def to_s
"The command timed out"
end
end
class WriteError < Error #:nodoc:
- def desc
+ def to_s
"The modem couldn't be written to. It " +\
"may have crashed or been unplugged"
end
end
class ReadError < Error #:nodoc:
- def desc
+ def to_s
"The modem couldn't be read from. It " +\
"may have crashed or been unplugged"
end
end
+
+ class ResetError < Error #:nodoc:
+ def to_s
+ "The modem could not be reset"
+ end
+ end
class AutoDetectError < Error #:nodoc:
- def desc
+ def to_s
"No modem could be auto-detected."
end
end

0 comments on commit 91e6309

Please sign in to comment.