]> git.openstreetmap.org Git - rails.git/commitdiff
Fix new rubocop warnings
authorTom Hughes <tom@compton.nu>
Tue, 23 Apr 2019 08:25:47 +0000 (09:25 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 23 Apr 2019 08:33:34 +0000 (09:33 +0100)
18 files changed:
app/controllers/api/amf_controller.rb
app/controllers/api/changesets_controller.rb
app/controllers/api/map_controller.rb
app/controllers/api/tracepoints_controller.rb
app/controllers/application_controller.rb
app/controllers/geocoder_controller.rb
app/controllers/traces_controller.rb
app/jobs/trace_importer_job.rb
app/models/changeset.rb
app/models/node.rb
app/models/relation.rb
app/models/trace.rb
app/models/way.rb
config/initializers/i18n.rb
lib/diff_reader.rb
test/controllers/api/changesets_controller_test.rb
test/controllers/api/old_nodes_controller_test.rb
test/models/message_test.rb

index 0cf511d76333cb7ba9d0975c9019fd3fabbc91b3..0f368c3dc009c7fdd0ea47014cdf0a043b2b1ecd 100644 (file)
@@ -114,18 +114,18 @@ module Api
 
     def amf_handle_error(call, rootobj, rootid)
       yield
-    rescue OSM::APIAlreadyDeletedError => ex
-      [-4, ex.object, ex.object_id]
-    rescue OSM::APIVersionMismatchError => ex
-      [-3, [rootobj, rootid], [ex.type.downcase, ex.id, ex.latest]]
-    rescue OSM::APIUserChangesetMismatchError => ex
-      [-2, ex.to_s]
-    rescue OSM::APIBadBoundingBox => ex
-      [-2, "Sorry - I can't get the map for that area. The server said: #{ex}"]
-    rescue OSM::APIError => ex
-      [-1, ex.to_s]
-    rescue StandardError => ex
-      [-2, "An unusual error happened (in #{call}). The server said: #{ex}"]
+    rescue OSM::APIAlreadyDeletedError => e
+      [-4, e.object, e.object_id]
+    rescue OSM::APIVersionMismatchError => e
+      [-3, [rootobj, rootid], [e.type.downcase, e.id, e.latest]]
+    rescue OSM::APIUserChangesetMismatchError => e
+      [-2, e.to_s]
+    rescue OSM::APIBadBoundingBox => e
+      [-2, "Sorry - I can't get the map for that area. The server said: #{e}"]
+    rescue OSM::APIError => e
+      [-1, e.to_s]
+    rescue StandardError => e
+      [-2, "An unusual error happened (in #{call}). The server said: #{e}"]
     end
 
     def amf_handle_error_with_timeout(call, rootobj, rootid)
index fb6523f4e0065a1dd9c508fc2c9e490e68cbfaaa..ffd9a112bb433048e55380b593fac7ecae0e7494 100644 (file)
@@ -364,10 +364,10 @@ module Api
       end
       # stupid Time seems to throw both of these for bad parsing, so
       # we have to catch both and ensure the correct code path is taken.
-    rescue ArgumentError => ex
-      raise OSM::APIBadUserInput, ex.message.to_s
-    rescue RuntimeError => ex
-      raise OSM::APIBadUserInput, ex.message.to_s
+    rescue ArgumentError => e
+      raise OSM::APIBadUserInput, e.message.to_s
+    rescue RuntimeError => e
+      raise OSM::APIBadUserInput, e.message.to_s
     end
 
     ##
index 27d6f3667410b13504851e0298e1eb67257c4154..e1d1a3b37844878661c9458fd41dd282a3396b81 100644 (file)
@@ -22,8 +22,8 @@ module Api
         bbox = BoundingBox.from_bbox_params(params)
         bbox.check_boundaries
         bbox.check_size
-      rescue StandardError => err
-        report_error(err.message)
+      rescue StandardError => e
+        report_error(e.message)
         return
       end
 
index b22bcfaeaff994508a4a7d2272035157e0867473..5fbece05b7a1eb08638cb6b8c64acad0897113ad 100644 (file)
@@ -25,8 +25,8 @@ module Api
         bbox = BoundingBox.from_bbox_params(params)
         bbox.check_boundaries
         bbox.check_size
-      rescue StandardError => err
-        report_error(err.message)
+      rescue StandardError => e
+        report_error(e.message)
         return
       end
 
index c880e6add00d756ec0b0d6c061a76d00bfa4e40c..bee5e8169a4709d05f5d36ead2c6924a03f2db6a 100644 (file)
@@ -37,8 +37,8 @@ class ApplicationController < ActionController::Base
     elsif session[:token]
       session[:user] = current_user.id if self.current_user = User.authenticate(:token => session[:token])
     end
-  rescue StandardError => ex
-    logger.info("Exception authorizing user: #{ex}")
+  rescue StandardError => e
+    logger.info("Exception authorizing user: #{e}")
     reset_session
     self.current_user = nil
   end
@@ -185,22 +185,22 @@ class ApplicationController < ActionController::Base
 
   def api_call_handle_error
     yield
-  rescue ActiveRecord::RecordNotFound => ex
+  rescue ActiveRecord::RecordNotFound => e
     head :not_found
-  rescue LibXML::XML::Error, ArgumentError => ex
-    report_error ex.message, :bad_request
-  rescue ActiveRecord::RecordInvalid => ex
-    message = "#{ex.record.class} #{ex.record.id}: "
-    ex.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{ex.record[attr].inspect})" }
+  rescue LibXML::XML::Error, ArgumentError => e
+    report_error e.message, :bad_request
+  rescue ActiveRecord::RecordInvalid => e
+    message = "#{e.record.class} #{e.record.id}: "
+    e.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{e.record[attr].inspect})" }
     report_error message, :bad_request
-  rescue OSM::APIError => ex
-    report_error ex.message, ex.status
-  rescue AbstractController::ActionNotFound => ex
+  rescue OSM::APIError => e
+    report_error e.message, e.status
+  rescue AbstractController::ActionNotFound => e
     raise
-  rescue StandardError => ex
-    logger.info("API threw unexpected #{ex.class} exception: #{ex.message}")
-    ex.backtrace.each { |l| logger.info(l) }
-    report_error "#{ex.class}: #{ex.message}", :internal_server_error
+  rescue StandardError => e
+    logger.info("API threw unexpected #{e.class} exception: #{e.message}")
+    e.backtrace.each { |l| logger.info(l) }
+    report_error "#{e.class}: #{e.message}", :internal_server_error
   end
 
   ##
@@ -227,11 +227,11 @@ class ApplicationController < ActionController::Base
     OSM::Timer.timeout(Settings.web_timeout, Timeout::Error) do
       yield
     end
-  rescue ActionView::Template::Error => ex
-    ex = ex.cause
+  rescue ActionView::Template::Error => e
+    e = e.cause
 
-    if ex.is_a?(Timeout::Error) ||
-       (ex.is_a?(ActiveRecord::StatementInvalid) && ex.message =~ /execution expired/)
+    if e.is_a?(Timeout::Error) ||
+       (e.is_a?(ActiveRecord::StatementInvalid) && e.message =~ /execution expired/)
       render :action => "timeout"
     else
       raise
index 4a8f7765065ab11c7f6db3caa668f37826f2fc4e..d1af43a724e17ea75778648cf7054a765bccc6ce 100644 (file)
@@ -98,8 +98,8 @@ class GeocoderController < ApplicationController
     end
 
     render :action => "results"
-  rescue StandardError => ex
-    @error = "Error contacting geocoder.ca: #{ex}"
+  rescue StandardError => e
+    @error = "Error contacting geocoder.ca: #{e}"
     render :action => "error"
   end
 
@@ -166,8 +166,8 @@ class GeocoderController < ApplicationController
     end
 
     render :action => "results"
-  rescue StandardError => ex
-    @error = "Error contacting nominatim.openstreetmap.org: #{ex}"
+  rescue StandardError => e
+    @error = "Error contacting nominatim.openstreetmap.org: #{e}"
     render :action => "error"
   end
 
@@ -198,8 +198,8 @@ class GeocoderController < ApplicationController
     end
 
     render :action => "results"
-  rescue StandardError => ex
-    @error = "Error contacting api.geonames.org: #{ex}"
+  rescue StandardError => e
+    @error = "Error contacting api.geonames.org: #{e}"
     render :action => "error"
   end
 
@@ -230,8 +230,8 @@ class GeocoderController < ApplicationController
     end
 
     render :action => "results"
-  rescue StandardError => ex
-    @error = "Error contacting nominatim.openstreetmap.org: #{ex}"
+  rescue StandardError => e
+    @error = "Error contacting nominatim.openstreetmap.org: #{e}"
     render :action => "error"
   end
 
@@ -261,8 +261,8 @@ class GeocoderController < ApplicationController
     end
 
     render :action => "results"
-  rescue StandardError => ex
-    @error = "Error contacting api.geonames.org: #{ex}"
+  rescue StandardError => e
+    @error = "Error contacting api.geonames.org: #{e}"
     render :action => "error"
   end
 
index 334aa2aa654fecbd13a3453e1fd53c076154ce57..3497e92d5fdc9348e80e3c9b6bbaf40036bd9a7f 100644 (file)
@@ -113,8 +113,8 @@ class TracesController < ApplicationController
       begin
         @trace = do_create(params[:trace][:gpx_file], params[:trace][:tagstring],
                            params[:trace][:description], params[:trace][:visibility])
-      rescue StandardError => ex
-        logger.debug ex
+      rescue StandardError => e
+        logger.debug e
       end
 
       if @trace.id
index 6b8943aa20f2dc5dca20dfdd979429f6f0096bbc..e4395bf3d378356f06fb9bd896e8e90862cbf8d9 100644 (file)
@@ -10,10 +10,10 @@ class TraceImporterJob < ApplicationJob
       Notifier.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver_later
       trace.destroy
     end
-  rescue StandardError => ex
-    logger.info ex.to_s
-    ex.backtrace.each { |l| logger.info l }
-    Notifier.gpx_failure(trace, ex.to_s + "\n" + ex.backtrace.join("\n")).deliver_later
+  rescue StandardError => e
+    logger.info e.to_s
+    e.backtrace.each { |l| logger.info l }
+    Notifier.gpx_failure(trace, e.to_s + "\n" + e.backtrace.join("\n")).deliver_later
     trace.destroy
   end
 end
index 3ca719f6cc663dff860a2157817d34966edb172c..b98d213c713015e205c7eaaaa4ab4853278b41ce 100644 (file)
@@ -88,8 +88,8 @@ class Changeset < ActiveRecord::Base
       return Changeset.from_xml_node(pt, create)
     end
     raise OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.")
-  rescue LibXML::XML::Error, ArgumentError => ex
-    raise OSM::APIBadXMLError.new("changeset", xml, ex.message)
+  rescue LibXML::XML::Error, ArgumentError => e
+    raise OSM::APIBadXMLError.new("changeset", xml, e.message)
   end
 
   def self.from_xml_node(pt, create = false)
index 989cdee5cd20cc4a5b86d910cfedd9d54eda79ca..be561fb5daa3eb15b30c9810d02d9aee5aa4eda2 100644 (file)
@@ -79,8 +79,8 @@ class Node < ActiveRecord::Base
       return Node.from_xml_node(pt, create)
     end
     raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.")
-  rescue LibXML::XML::Error, ArgumentError => ex
-    raise OSM::APIBadXMLError.new("node", xml, ex.message)
+  rescue LibXML::XML::Error, ArgumentError => e
+    raise OSM::APIBadXMLError.new("node", xml, e.message)
   end
 
   def self.from_xml_node(pt, create = false)
index f55711a69bb75b060ae7a0ec61a120afbf852657..884e96ed7c120d5c20c2448753d4795df12a273e 100644 (file)
@@ -62,8 +62,8 @@ class Relation < ActiveRecord::Base
       return Relation.from_xml_node(pt, create)
     end
     raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.")
-  rescue LibXML::XML::Error, ArgumentError => ex
-    raise OSM::APIBadXMLError.new("relation", xml, ex.message)
+  rescue LibXML::XML::Error, ArgumentError => e
+    raise OSM::APIBadXMLError.new("relation", xml, e.message)
   end
 
   def self.from_xml_node(pt, create = false)
index 0e876332874487acbafb3c5b17013e0cbb2b579b..1a2dfc9e49a6695b10d57b1e3c97bfbdc510cf86 100644 (file)
@@ -208,8 +208,8 @@ class Trace < ActiveRecord::Base
     end
 
     raise OSM::APIBadXMLError.new("trace", xml, "XML doesn't contain an osm/gpx_file element.")
-  rescue LibXML::XML::Error, ArgumentError => ex
-    raise OSM::APIBadXMLError.new("trace", xml, ex.message)
+  rescue LibXML::XML::Error, ArgumentError => e
+    raise OSM::APIBadXMLError.new("trace", xml, e.message)
   end
 
   def update_from_xml_node(pt, create = false)
index 6573b9805ecc449aac0b365e5a9a31798b86f2c2..ddb82ed1ed486965c4d4fe873decdb0e1f0f2e11 100644 (file)
@@ -60,8 +60,8 @@ class Way < ActiveRecord::Base
       return Way.from_xml_node(pt, create)
     end
     raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.")
-  rescue LibXML::XML::Error, ArgumentError => ex
-    raise OSM::APIBadXMLError.new("way", xml, ex.message)
+  rescue LibXML::XML::Error, ArgumentError => e
+    raise OSM::APIBadXMLError.new("way", xml, e.message)
   end
 
   def self.from_xml_node(pt, create = false)
index b4399a9f868348640deece25f915345fda95fe5a..6e09300170d239d2fbc9171d90ffca06cc2d265d 100644 (file)
@@ -3,10 +3,10 @@ module I18n
     module PluralizationFallback
       def pluralize(locale, entry, count)
         super
-      rescue InvalidPluralizationData => ex
-        raise ex unless ex.entry.key?(:other)
+      rescue InvalidPluralizationData => e
+        raise e unless e.entry.key?(:other)
 
-        ex.entry[:other]
+        e.entry[:other]
       end
     end
   end
index e3c533b7af6e8357a1a6b821792b2da6cbb0e3df..19e0b8afc6bb8f7033c385153fc13834a3b49189 100644 (file)
@@ -33,8 +33,8 @@ class DiffReader
     # NOTE: XML::Reader#read returns false for EOF and raises an
     # exception if an error occurs.
     @reader.read
-  rescue LibXML::XML::Error => ex
-    raise OSM::APIBadXMLError.new("changeset", xml, ex.message)
+  rescue LibXML::XML::Error => e
+    raise OSM::APIBadXMLError.new("changeset", xml, e.message)
   end
 
   ##
index f9643685f25ae144bda51b75d8ab471956903d24..9f2b64c0a35a956ffd89e70d9e620769c767a1c4 100644 (file)
@@ -176,8 +176,8 @@ module Api
       [0, -32, 233455644, "afg", "213"].each do |id|
         get :show, :params => { :id => id }
         assert_response :not_found, "should get a not found"
-      rescue ActionController::UrlGenerationError => ex
-        assert_match(/No route matches/, ex.to_s)
+      rescue ActionController::UrlGenerationError => e
+        assert_match(/No route matches/, e.to_s)
       end
     end
 
@@ -248,8 +248,8 @@ module Api
       cs_ids.each do |id|
         put :close, :params => { :id => id }
         assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
-      rescue ActionController::UrlGenerationError => ex
-        assert_match(/No route matches/, ex.to_s)
+      rescue ActionController::UrlGenerationError => e
+        assert_match(/No route matches/, e.to_s)
       end
 
       # Now try with auth
@@ -257,8 +257,8 @@ module Api
       cs_ids.each do |id|
         put :close, :params => { :id => id }
         assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
-      rescue ActionController::UrlGenerationError => ex
-        assert_match(/No route matches/, ex.to_s)
+      rescue ActionController::UrlGenerationError => e
+        assert_match(/No route matches/, e.to_s)
       end
     end
 
index 375a553b8fab2a266b3e840a9999fdd31c825c0e..0f8954541034c726d68c15b71462d9146fbeaf71 100644 (file)
@@ -156,8 +156,8 @@ module Api
     def check_not_found_id_version(id, version)
       get :version, :params => { :id => id, :version => version }
       assert_response :not_found
-    rescue ActionController::UrlGenerationError => ex
-      assert_match(/No route matches/, ex.to_s)
+    rescue ActionController::UrlGenerationError => e
+      assert_match(/No route matches/, e.to_s)
     end
 
     ##
index 9c321d3c39c7ff5c317a14235d393c40d011ae5d..60ff19e4467e616c1cb2a91608dddbf016fdcd6d 100644 (file)
@@ -63,8 +63,8 @@ class MessageTest < ActiveSupport::TestCase
       # its OK to accept invalid UTF-8 as long as we return it unmodified.
       db_msg = msg.class.find(msg.id)
       assert_equal char, db_msg.title, "Database silently truncated message title"
-    rescue ArgumentError => ex
-      assert_equal ex.to_s, "invalid byte sequence in UTF-8"
+    rescue ArgumentError => e
+      assert_equal e.to_s, "invalid byte sequence in UTF-8"
     end
   end