module OGR::ErrorHandling
OGR
returns errors as Integers–not as part of the GDAL/CPLErr error handling callback interface. This hacks together a facility for sort of doing that with OGR
.
Unlike the OGR
API, ffi-gdal defines an Enum for the OGRERR types, which in turns causes OGR
to return Symbols on errors (the defines for those can be found here: www.gdal.org/ogr__core_8h.html). This maps those Symbols to Ruby exceptions (or lack thereof).
Constants
- ERROR_CLASS_MAP
Public Class Methods
handle_ogr_err(msg) { || ... }
click to toggle source
Yields, then expects the result to be a Symbol from FFI::OGR::Core::Err.
@param msg [String]
# File lib/ogr/error_handling.rb, line 30 def self.handle_ogr_err(msg) ogr_err_symbol = yield klass = ERROR_CLASS_MAP.fetch(ogr_err_symbol) { raise "Unknown OGRERR type: #{self}" } raise_exception(klass, msg) if klass end
raise_exception(exception, message)
click to toggle source
Exists solely to strip off the top 4 lines of the backtrace so it doesn’t look like the problem is coming from here.
# File lib/ogr/error_handling.rb, line 40 def self.raise_exception(exception, message) e = exception.new(message) e.set_backtrace(caller(2)) raise(e) end