Fix new rubocop warnings

This commit is contained in:
Tom Hughes 2019-04-23 09:25:47 +01:00
parent 7354c8eb13
commit 9f57f60b87
18 changed files with 80 additions and 80 deletions

View file

@ -114,18 +114,18 @@ module Api
def amf_handle_error(call, rootobj, rootid) def amf_handle_error(call, rootobj, rootid)
yield yield
rescue OSM::APIAlreadyDeletedError => ex rescue OSM::APIAlreadyDeletedError => e
[-4, ex.object, ex.object_id] [-4, e.object, e.object_id]
rescue OSM::APIVersionMismatchError => ex rescue OSM::APIVersionMismatchError => e
[-3, [rootobj, rootid], [ex.type.downcase, ex.id, ex.latest]] [-3, [rootobj, rootid], [e.type.downcase, e.id, e.latest]]
rescue OSM::APIUserChangesetMismatchError => ex rescue OSM::APIUserChangesetMismatchError => e
[-2, ex.to_s] [-2, e.to_s]
rescue OSM::APIBadBoundingBox => ex rescue OSM::APIBadBoundingBox => e
[-2, "Sorry - I can't get the map for that area. The server said: #{ex}"] [-2, "Sorry - I can't get the map for that area. The server said: #{e}"]
rescue OSM::APIError => ex rescue OSM::APIError => e
[-1, ex.to_s] [-1, e.to_s]
rescue StandardError => ex rescue StandardError => e
[-2, "An unusual error happened (in #{call}). The server said: #{ex}"] [-2, "An unusual error happened (in #{call}). The server said: #{e}"]
end end
def amf_handle_error_with_timeout(call, rootobj, rootid) def amf_handle_error_with_timeout(call, rootobj, rootid)

View file

@ -364,10 +364,10 @@ module Api
end end
# stupid Time seems to throw both of these for bad parsing, so # 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. # we have to catch both and ensure the correct code path is taken.
rescue ArgumentError => ex rescue ArgumentError => e
raise OSM::APIBadUserInput, ex.message.to_s raise OSM::APIBadUserInput, e.message.to_s
rescue RuntimeError => ex rescue RuntimeError => e
raise OSM::APIBadUserInput, ex.message.to_s raise OSM::APIBadUserInput, e.message.to_s
end end
## ##

View file

@ -22,8 +22,8 @@ module Api
bbox = BoundingBox.from_bbox_params(params) bbox = BoundingBox.from_bbox_params(params)
bbox.check_boundaries bbox.check_boundaries
bbox.check_size bbox.check_size
rescue StandardError => err rescue StandardError => e
report_error(err.message) report_error(e.message)
return return
end end

View file

@ -25,8 +25,8 @@ module Api
bbox = BoundingBox.from_bbox_params(params) bbox = BoundingBox.from_bbox_params(params)
bbox.check_boundaries bbox.check_boundaries
bbox.check_size bbox.check_size
rescue StandardError => err rescue StandardError => e
report_error(err.message) report_error(e.message)
return return
end end

View file

@ -37,8 +37,8 @@ class ApplicationController < ActionController::Base
elsif session[:token] elsif session[:token]
session[:user] = current_user.id if self.current_user = User.authenticate(:token => session[:token]) session[:user] = current_user.id if self.current_user = User.authenticate(:token => session[:token])
end end
rescue StandardError => ex rescue StandardError => e
logger.info("Exception authorizing user: #{ex}") logger.info("Exception authorizing user: #{e}")
reset_session reset_session
self.current_user = nil self.current_user = nil
end end
@ -185,22 +185,22 @@ class ApplicationController < ActionController::Base
def api_call_handle_error def api_call_handle_error
yield yield
rescue ActiveRecord::RecordNotFound => ex rescue ActiveRecord::RecordNotFound => e
head :not_found head :not_found
rescue LibXML::XML::Error, ArgumentError => ex rescue LibXML::XML::Error, ArgumentError => e
report_error ex.message, :bad_request report_error e.message, :bad_request
rescue ActiveRecord::RecordInvalid => ex rescue ActiveRecord::RecordInvalid => e
message = "#{ex.record.class} #{ex.record.id}: " message = "#{e.record.class} #{e.record.id}: "
ex.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{ex.record[attr].inspect})" } e.record.errors.each { |attr, msg| message << "#{attr}: #{msg} (#{e.record[attr].inspect})" }
report_error message, :bad_request report_error message, :bad_request
rescue OSM::APIError => ex rescue OSM::APIError => e
report_error ex.message, ex.status report_error e.message, e.status
rescue AbstractController::ActionNotFound => ex rescue AbstractController::ActionNotFound => e
raise raise
rescue StandardError => ex rescue StandardError => e
logger.info("API threw unexpected #{ex.class} exception: #{ex.message}") logger.info("API threw unexpected #{e.class} exception: #{e.message}")
ex.backtrace.each { |l| logger.info(l) } e.backtrace.each { |l| logger.info(l) }
report_error "#{ex.class}: #{ex.message}", :internal_server_error report_error "#{e.class}: #{e.message}", :internal_server_error
end end
## ##
@ -227,11 +227,11 @@ class ApplicationController < ActionController::Base
OSM::Timer.timeout(Settings.web_timeout, Timeout::Error) do OSM::Timer.timeout(Settings.web_timeout, Timeout::Error) do
yield yield
end end
rescue ActionView::Template::Error => ex rescue ActionView::Template::Error => e
ex = ex.cause e = e.cause
if ex.is_a?(Timeout::Error) || if e.is_a?(Timeout::Error) ||
(ex.is_a?(ActiveRecord::StatementInvalid) && ex.message =~ /execution expired/) (e.is_a?(ActiveRecord::StatementInvalid) && e.message =~ /execution expired/)
render :action => "timeout" render :action => "timeout"
else else
raise raise

View file

@ -98,8 +98,8 @@ class GeocoderController < ApplicationController
end end
render :action => "results" render :action => "results"
rescue StandardError => ex rescue StandardError => e
@error = "Error contacting geocoder.ca: #{ex}" @error = "Error contacting geocoder.ca: #{e}"
render :action => "error" render :action => "error"
end end
@ -166,8 +166,8 @@ class GeocoderController < ApplicationController
end end
render :action => "results" render :action => "results"
rescue StandardError => ex rescue StandardError => e
@error = "Error contacting nominatim.openstreetmap.org: #{ex}" @error = "Error contacting nominatim.openstreetmap.org: #{e}"
render :action => "error" render :action => "error"
end end
@ -198,8 +198,8 @@ class GeocoderController < ApplicationController
end end
render :action => "results" render :action => "results"
rescue StandardError => ex rescue StandardError => e
@error = "Error contacting api.geonames.org: #{ex}" @error = "Error contacting api.geonames.org: #{e}"
render :action => "error" render :action => "error"
end end
@ -230,8 +230,8 @@ class GeocoderController < ApplicationController
end end
render :action => "results" render :action => "results"
rescue StandardError => ex rescue StandardError => e
@error = "Error contacting nominatim.openstreetmap.org: #{ex}" @error = "Error contacting nominatim.openstreetmap.org: #{e}"
render :action => "error" render :action => "error"
end end
@ -261,8 +261,8 @@ class GeocoderController < ApplicationController
end end
render :action => "results" render :action => "results"
rescue StandardError => ex rescue StandardError => e
@error = "Error contacting api.geonames.org: #{ex}" @error = "Error contacting api.geonames.org: #{e}"
render :action => "error" render :action => "error"
end end

View file

@ -113,8 +113,8 @@ class TracesController < ApplicationController
begin begin
@trace = do_create(params[:trace][:gpx_file], params[:trace][:tagstring], @trace = do_create(params[:trace][:gpx_file], params[:trace][:tagstring],
params[:trace][:description], params[:trace][:visibility]) params[:trace][:description], params[:trace][:visibility])
rescue StandardError => ex rescue StandardError => e
logger.debug ex logger.debug e
end end
if @trace.id if @trace.id

View 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 Notifier.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver_later
trace.destroy trace.destroy
end end
rescue StandardError => ex rescue StandardError => e
logger.info ex.to_s logger.info e.to_s
ex.backtrace.each { |l| logger.info l } e.backtrace.each { |l| logger.info l }
Notifier.gpx_failure(trace, ex.to_s + "\n" + ex.backtrace.join("\n")).deliver_later Notifier.gpx_failure(trace, e.to_s + "\n" + e.backtrace.join("\n")).deliver_later
trace.destroy trace.destroy
end end
end end

View file

@ -88,8 +88,8 @@ class Changeset < ActiveRecord::Base
return Changeset.from_xml_node(pt, create) return Changeset.from_xml_node(pt, create)
end end
raise OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.") raise OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.")
rescue LibXML::XML::Error, ArgumentError => ex rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("changeset", xml, ex.message) raise OSM::APIBadXMLError.new("changeset", xml, e.message)
end end
def self.from_xml_node(pt, create = false) def self.from_xml_node(pt, create = false)

View file

@ -79,8 +79,8 @@ class Node < ActiveRecord::Base
return Node.from_xml_node(pt, create) return Node.from_xml_node(pt, create)
end end
raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.") raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.")
rescue LibXML::XML::Error, ArgumentError => ex rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("node", xml, ex.message) raise OSM::APIBadXMLError.new("node", xml, e.message)
end end
def self.from_xml_node(pt, create = false) def self.from_xml_node(pt, create = false)

View file

@ -62,8 +62,8 @@ class Relation < ActiveRecord::Base
return Relation.from_xml_node(pt, create) return Relation.from_xml_node(pt, create)
end end
raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.") raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.")
rescue LibXML::XML::Error, ArgumentError => ex rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("relation", xml, ex.message) raise OSM::APIBadXMLError.new("relation", xml, e.message)
end end
def self.from_xml_node(pt, create = false) def self.from_xml_node(pt, create = false)

View file

@ -208,8 +208,8 @@ class Trace < ActiveRecord::Base
end end
raise OSM::APIBadXMLError.new("trace", xml, "XML doesn't contain an osm/gpx_file element.") raise OSM::APIBadXMLError.new("trace", xml, "XML doesn't contain an osm/gpx_file element.")
rescue LibXML::XML::Error, ArgumentError => ex rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("trace", xml, ex.message) raise OSM::APIBadXMLError.new("trace", xml, e.message)
end end
def update_from_xml_node(pt, create = false) def update_from_xml_node(pt, create = false)

View file

@ -60,8 +60,8 @@ class Way < ActiveRecord::Base
return Way.from_xml_node(pt, create) return Way.from_xml_node(pt, create)
end end
raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.") raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.")
rescue LibXML::XML::Error, ArgumentError => ex rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("way", xml, ex.message) raise OSM::APIBadXMLError.new("way", xml, e.message)
end end
def self.from_xml_node(pt, create = false) def self.from_xml_node(pt, create = false)

View file

@ -3,10 +3,10 @@ module I18n
module PluralizationFallback module PluralizationFallback
def pluralize(locale, entry, count) def pluralize(locale, entry, count)
super super
rescue InvalidPluralizationData => ex rescue InvalidPluralizationData => e
raise ex unless ex.entry.key?(:other) raise e unless e.entry.key?(:other)
ex.entry[:other] e.entry[:other]
end end
end end
end end

View file

@ -33,8 +33,8 @@ class DiffReader
# NOTE: XML::Reader#read returns false for EOF and raises an # NOTE: XML::Reader#read returns false for EOF and raises an
# exception if an error occurs. # exception if an error occurs.
@reader.read @reader.read
rescue LibXML::XML::Error => ex rescue LibXML::XML::Error => e
raise OSM::APIBadXMLError.new("changeset", xml, ex.message) raise OSM::APIBadXMLError.new("changeset", xml, e.message)
end end
## ##

View file

@ -176,8 +176,8 @@ module Api
[0, -32, 233455644, "afg", "213"].each do |id| [0, -32, 233455644, "afg", "213"].each do |id|
get :show, :params => { :id => id } get :show, :params => { :id => id }
assert_response :not_found, "should get a not found" assert_response :not_found, "should get a not found"
rescue ActionController::UrlGenerationError => ex rescue ActionController::UrlGenerationError => e
assert_match(/No route matches/, ex.to_s) assert_match(/No route matches/, e.to_s)
end end
end end
@ -248,8 +248,8 @@ module Api
cs_ids.each do |id| cs_ids.each do |id|
put :close, :params => { :id => id } put :close, :params => { :id => id }
assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized" assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
rescue ActionController::UrlGenerationError => ex rescue ActionController::UrlGenerationError => e
assert_match(/No route matches/, ex.to_s) assert_match(/No route matches/, e.to_s)
end end
# Now try with auth # Now try with auth
@ -257,8 +257,8 @@ module Api
cs_ids.each do |id| cs_ids.each do |id|
put :close, :params => { :id => id } put :close, :params => { :id => id }
assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed" assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
rescue ActionController::UrlGenerationError => ex rescue ActionController::UrlGenerationError => e
assert_match(/No route matches/, ex.to_s) assert_match(/No route matches/, e.to_s)
end end
end end

View file

@ -156,8 +156,8 @@ module Api
def check_not_found_id_version(id, version) def check_not_found_id_version(id, version)
get :version, :params => { :id => id, :version => version } get :version, :params => { :id => id, :version => version }
assert_response :not_found assert_response :not_found
rescue ActionController::UrlGenerationError => ex rescue ActionController::UrlGenerationError => e
assert_match(/No route matches/, ex.to_s) assert_match(/No route matches/, e.to_s)
end end
## ##

View file

@ -63,8 +63,8 @@ class MessageTest < ActiveSupport::TestCase
# its OK to accept invalid UTF-8 as long as we return it unmodified. # its OK to accept invalid UTF-8 as long as we return it unmodified.
db_msg = msg.class.find(msg.id) db_msg = msg.class.find(msg.id)
assert_equal char, db_msg.title, "Database silently truncated message title" assert_equal char, db_msg.title, "Database silently truncated message title"
rescue ArgumentError => ex rescue ArgumentError => e
assert_equal ex.to_s, "invalid byte sequence in UTF-8" assert_equal e.to_s, "invalid byte sequence in UTF-8"
end end
end end