1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use libc::{c_int};
use gdal_sys::cpl_error::CPLErr;
use gdal_sys::ogr_enums::{OGRErr, OGRFieldType};

// Create the Error, ErrorKind, ResultExt, and Result types
error_chain! {
    foreign_links {
        FfiNulError(::std::ffi::NulError);
        StrUtf8Error(::std::str::Utf8Error);
    }

    errors {
        CplError(class: CPLErr, number: c_int, msg: String) {
            description("GDAL internal error")
            display("CPL error class: '{:?}', error number: '{}', error msg: '{}'", class, number, msg)
        }
        NullPointer(method_name: &'static str, msg: String) {
            description("GDAL method returned a NULL pointer.")
            display("GDAL method '{}' returned a NULL pointer. Error msg: '{}'", method_name, msg)
        }
        OgrError(err: OGRErr, method_name: &'static str) {
            description("OGR error")
            display("OGR method '{}' returned error: '{:?}'", method_name, err)
        }
        UnhandledFieldType(field_type: OGRFieldType, method_name: &'static str){
            description("Unhandled field type")
            display("Unhandled type {:?} on OGR method {}", field_type, method_name)
        }
        InvalidFieldName(field_name: String, method_name: &'static str){
            description("Invalid field name error")
            display("Invalid field name '{}' used on method {}", field_name, method_name)
        }
        InvalidFieldIndex(index: usize, method_name: &'static str){
            description("Invalid field index error")
            display("Invalid field index {} used on method {}", index, method_name)
        }
        UnlinkedGeometry(method_name: &'static str){
            description("Unlinked Geometry")
            display("Unlinked Geometry on method {}", method_name)
        }
    }
}