Merge pull request #912 from matthiasbeyer/libimagruby/error-types
Libimagruby/error types
This commit is contained in:
commit
3a0166ba7c
5 changed files with 105 additions and 26 deletions
|
@ -79,11 +79,11 @@ macro_rules! call_on_fle_from_store {
|
||||||
$operation
|
$operation
|
||||||
},
|
},
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), "Obj does not exist");
|
VM::raise(Class::from_existing("RImagStoreReadError"), "Obj does not exist");
|
||||||
NilClass::new().to_any_object()
|
NilClass::new().to_any_object()
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreReadError"), e.description());
|
||||||
NilClass::new().to_any_object()
|
NilClass::new().to_any_object()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -100,11 +100,11 @@ macro_rules! call_on_fle_from_store {
|
||||||
$operation
|
$operation
|
||||||
},
|
},
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), "Obj does not exist");
|
VM::raise(Class::from_existing("RImagStoreReadError"), "Obj does not exist");
|
||||||
$ex
|
$ex
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreReadError"), e.description());
|
||||||
$ex
|
$ex
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ methods!(
|
||||||
let entryheader = match typecheck!(hdr or return NilClass::new()).into_toml() {
|
let entryheader = match typecheck!(hdr or return NilClass::new()).into_toml() {
|
||||||
Value::Table(t) => Value::Table(t),
|
Value::Table(t) => Value::Table(t),
|
||||||
_ => {
|
_ => {
|
||||||
let ec = Class::from_existing("RuntimeError");
|
let ec = Class::from_existing("RImagEntryHeaderWriteError");
|
||||||
VM::raise(ec, "Something weird happened. Hash seems to be not a Hash");
|
VM::raise(ec, "Something weird happened. Hash seems to be not a Hash");
|
||||||
return NilClass::new();
|
return NilClass::new();
|
||||||
},
|
},
|
||||||
|
@ -160,7 +160,7 @@ methods!(
|
||||||
let content = match typecheck!(ctt).into_toml() {
|
let content = match typecheck!(ctt).into_toml() {
|
||||||
Value::String(s) => s,
|
Value::String(s) => s,
|
||||||
_ => {
|
_ => {
|
||||||
let ec = Class::from_existing("RuntimeError");
|
let ec = Class::from_existing("RImagEntryError");
|
||||||
VM::raise(ec, "Something weird happened. String seems to be not a String");
|
VM::raise(ec, "Something weird happened. String seems to be not a String");
|
||||||
return NilClass::new();
|
return NilClass::new();
|
||||||
},
|
},
|
||||||
|
@ -197,7 +197,7 @@ methods!(
|
||||||
match itself.get_data(&*ENTRY_HEADER_WRAPPER).insert(&spec, obj.into_toml()) {
|
match itself.get_data(&*ENTRY_HEADER_WRAPPER).insert(&spec, obj.into_toml()) {
|
||||||
Ok(b) => Boolean::new(b),
|
Ok(b) => Boolean::new(b),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagEntryHeaderWriteError"), e.description());
|
||||||
Boolean::new(false)
|
Boolean::new(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ methods!(
|
||||||
Ok(Some(v)) => v.into_ruby(),
|
Ok(Some(v)) => v.into_ruby(),
|
||||||
Ok(None) => NilClass::new().to_any_object(),
|
Ok(None) => NilClass::new().to_any_object(),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagEntryHeaderWriteError"), e.description());
|
||||||
return Boolean::new(false).to_any_object();
|
return Boolean::new(false).to_any_object();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ methods!(
|
||||||
Ok(Some(v)) => v.into_ruby(),
|
Ok(Some(v)) => v.into_ruby(),
|
||||||
Ok(None) => NilClass::new().to_any_object(),
|
Ok(None) => NilClass::new().to_any_object(),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagEntryHeaderReadError"), e.description());
|
||||||
return Boolean::new(false).to_any_object();
|
return Boolean::new(false).to_any_object();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
52
libimagruby/src/error.rs
Normal file
52
libimagruby/src/error.rs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; version
|
||||||
|
// 2.1 of the License.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
//
|
||||||
|
|
||||||
|
use ruru::Class;
|
||||||
|
|
||||||
|
class!(RImagError);
|
||||||
|
class!(RImagObjDoesNotExistError);
|
||||||
|
class!(RImagStoreError);
|
||||||
|
class!(RImagStoreWriteError);
|
||||||
|
class!(RImagStoreReadError);
|
||||||
|
class!(RImagEntryError);
|
||||||
|
class!(RImagEntryHeaderError);
|
||||||
|
class!(RImagEntryHeaderReadError);
|
||||||
|
class!(RImagEntryHeaderWriteError);
|
||||||
|
class!(RImagTypeError);
|
||||||
|
|
||||||
|
pub fn setup() {
|
||||||
|
let imag_error = Class::new("RImagError", Some(&Class::from_existing("RuntimeError")));
|
||||||
|
Class::new("RImagObjDoesNotExistError" , Some(&imag_error));
|
||||||
|
|
||||||
|
{
|
||||||
|
let imag_store_error = Class::new("RImagStoreError", Some(&imag_error));
|
||||||
|
Class::new("RImagStoreWriteError", Some(&imag_store_error));
|
||||||
|
Class::new("RImagStoreReadError" , Some(&imag_store_error));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let imag_entry_error = Class::new("RImagEntryError" , Some(&imag_error));
|
||||||
|
let imag_entry_header_error = Class::new("RImagEntryHeaderError", Some(&imag_entry_error));
|
||||||
|
Class::new("RImagEntryHeaderReadError" , Some(&imag_entry_header_error));
|
||||||
|
Class::new("RImagEntryHeaderWriteError", Some(&imag_entry_header_error));
|
||||||
|
}
|
||||||
|
|
||||||
|
Class::new("RImagTypeError", Some(&imag_error));
|
||||||
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ extern crate libimagrt;
|
||||||
#[macro_use] pub mod store;
|
#[macro_use] pub mod store;
|
||||||
mod cache;
|
mod cache;
|
||||||
|
|
||||||
|
pub mod error;
|
||||||
pub mod entry;
|
pub mod entry;
|
||||||
pub mod imag;
|
pub mod imag;
|
||||||
pub mod ruby_utils;
|
pub mod ruby_utils;
|
||||||
|
@ -43,6 +44,7 @@ pub mod toml_utils;
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub extern fn Init_liblibimagruby() {
|
pub extern fn Init_liblibimagruby() {
|
||||||
|
self::error::setup();
|
||||||
self::store::setup();
|
self::store::setup();
|
||||||
self::storeid::setup();
|
self::storeid::setup();
|
||||||
self::entry::setup_filelockentry();
|
self::entry::setup_filelockentry();
|
||||||
|
|
|
@ -61,14 +61,14 @@ macro_rules! call_on_store_by_handle {
|
||||||
match hm.get($store_handle) {
|
match hm.get($store_handle) {
|
||||||
Some($name) => { $operation },
|
Some($name) => { $operation },
|
||||||
None => {
|
None => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"),
|
VM::raise(Class::from_existing("RImagStoreReadError"),
|
||||||
"Tried to operate on non-existing object");
|
"Tried to operate on non-existing object");
|
||||||
$ex
|
$ex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagError"), e.description());
|
||||||
$ex
|
$ex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,11 +102,11 @@ macro_rules! call_on_store {
|
||||||
let $fle_name = match $store_name.get($fle_handle_name) {
|
let $fle_name = match $store_name.get($fle_handle_name) {
|
||||||
Ok(Some(fle)) => fle,
|
Ok(Some(fle)) => fle,
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), "Obj does not exist");
|
VM::raise(Class::from_existing("RImagStoreReadError"), "Obj does not exist");
|
||||||
return $fail_expr
|
return $fail_expr
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreReadError"), e.description());
|
||||||
return $fail_expr
|
return $fail_expr
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -174,14 +174,14 @@ methods!(
|
||||||
let rtp = PathBuf::from(typecheck!(rtp or return any NilClass::new()).to_string());
|
let rtp = PathBuf::from(typecheck!(rtp or return any NilClass::new()).to_string());
|
||||||
|
|
||||||
if !rtp.exists() || !rtp.is_dir() {
|
if !rtp.exists() || !rtp.is_dir() {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), "Runtimepath not a directory");
|
VM::raise(Class::from_existing("RImagError"), "Runtimepath not a directory");
|
||||||
return NilClass::new().to_any_object();
|
return NilClass::new().to_any_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
let store_config = match Configuration::new(&rtp) {
|
let store_config = match Configuration::new(&rtp) {
|
||||||
Ok(mut cfg) => cfg.store_config().cloned(),
|
Ok(mut cfg) => cfg.store_config().cloned(),
|
||||||
Err(e) => if e.err_type() != ConfigErrorKind::NoConfigFileFound {
|
Err(e) => if e.err_type() != ConfigErrorKind::NoConfigFileFound {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagError"), e.description());
|
||||||
return NilClass::new().to_any_object();
|
return NilClass::new().to_any_object();
|
||||||
} else {
|
} else {
|
||||||
warn!("No config file found.");
|
warn!("No config file found.");
|
||||||
|
@ -248,7 +248,7 @@ methods!(
|
||||||
let store = match store {
|
let store = match store {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreError"), e.description());
|
||||||
return NilClass::new().to_any_object();
|
return NilClass::new().to_any_object();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -264,7 +264,7 @@ methods!(
|
||||||
return store_handle.wrap().to_any_object();
|
return store_handle.wrap().to_any_object();
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagError"), e.description());
|
||||||
return NilClass::new().to_any_object();
|
return NilClass::new().to_any_object();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ methods!(
|
||||||
match store.create(sid.clone()) {
|
match store.create(sid.clone()) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
|
||||||
NilClass::new().to_any_object()
|
NilClass::new().to_any_object()
|
||||||
},
|
},
|
||||||
Ok(entry) => {
|
Ok(entry) => {
|
||||||
|
@ -325,7 +325,7 @@ methods!(
|
||||||
match store.retrieve(sid.clone()) {
|
match store.retrieve(sid.clone()) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
|
||||||
NilClass::new().to_any_object()
|
NilClass::new().to_any_object()
|
||||||
},
|
},
|
||||||
Ok(entry) => {
|
Ok(entry) => {
|
||||||
|
@ -360,7 +360,7 @@ methods!(
|
||||||
match store.get(sid.clone()) {
|
match store.get(sid.clone()) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
|
||||||
NilClass::new().to_any_object()
|
NilClass::new().to_any_object()
|
||||||
},
|
},
|
||||||
Ok(None) => NilClass::new().to_any_object(),
|
Ok(None) => NilClass::new().to_any_object(),
|
||||||
|
@ -397,7 +397,7 @@ methods!(
|
||||||
match store.retrieve_for_module(&name) {
|
match store.retrieve_for_module(&name) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
|
||||||
NilClass::new().to_any_object()
|
NilClass::new().to_any_object()
|
||||||
},
|
},
|
||||||
Ok(iter) => {
|
Ok(iter) => {
|
||||||
|
@ -428,7 +428,7 @@ methods!(
|
||||||
operation {
|
operation {
|
||||||
if let Err(e) = store.update(real_fle) {
|
if let Err(e) = store.update(real_fle) {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
|
||||||
}
|
}
|
||||||
NilClass::new()
|
NilClass::new()
|
||||||
},
|
},
|
||||||
|
@ -451,7 +451,7 @@ methods!(
|
||||||
operation {
|
operation {
|
||||||
if let Err(e) = store.delete(sid) {
|
if let Err(e) = store.delete(sid) {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
|
||||||
}
|
}
|
||||||
NilClass::new()
|
NilClass::new()
|
||||||
},
|
},
|
||||||
|
@ -476,7 +476,7 @@ methods!(
|
||||||
operation {
|
operation {
|
||||||
if let Err(e) = store.save_to(&real_fle, sid) {
|
if let Err(e) = store.save_to(&real_fle, sid) {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
|
||||||
}
|
}
|
||||||
NilClass::new()
|
NilClass::new()
|
||||||
},
|
},
|
||||||
|
@ -501,7 +501,7 @@ methods!(
|
||||||
operation {
|
operation {
|
||||||
if let Err(e) = store.save_as(real_fle, sid) {
|
if let Err(e) = store.save_as(real_fle, sid) {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
|
||||||
}
|
}
|
||||||
NilClass::new()
|
NilClass::new()
|
||||||
},
|
},
|
||||||
|
@ -525,7 +525,7 @@ methods!(
|
||||||
operation {
|
operation {
|
||||||
if let Err(e) = store.move_by_id(old, nw) {
|
if let Err(e) = store.move_by_id(old, nw) {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
VM::raise(Class::from_existing("RuntimeError"), e.description());
|
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
|
||||||
}
|
}
|
||||||
NilClass::new()
|
NilClass::new()
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,6 +30,31 @@ end
|
||||||
|
|
||||||
puts "---"
|
puts "---"
|
||||||
|
|
||||||
|
[
|
||||||
|
:RImag,
|
||||||
|
:RStoreId,
|
||||||
|
:RStoreHandle,
|
||||||
|
:RFileLockEntryHandle,
|
||||||
|
:REntryHeader,
|
||||||
|
:REntryContent,
|
||||||
|
:RImagError,
|
||||||
|
:RImagObjDoesNotExistError,
|
||||||
|
:RImagStoreError,
|
||||||
|
:RImagStoreWriteError,
|
||||||
|
:RImagStoreReadError,
|
||||||
|
:RImagEntryError,
|
||||||
|
:RImagEntryHeaderError,
|
||||||
|
:RImagEntryHeaderReadError,
|
||||||
|
:RImagEntryHeaderWriteError,
|
||||||
|
:RImagTypeError,
|
||||||
|
].each do |sym|
|
||||||
|
if Kernel.const_defined? sym
|
||||||
|
RImag.info "Exists: #{sym}"
|
||||||
|
else
|
||||||
|
RImag.error "#{sym} not defined"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
works "RStoreId.new_baseless", (not RStoreId.new_baseless("test").nil?)
|
works "RStoreId.new_baseless", (not RStoreId.new_baseless("test").nil?)
|
||||||
|
|
||||||
works "RStoreHandle.respond_to? :new", (RStoreHandle.respond_to? :new)
|
works "RStoreHandle.respond_to? :new", (RStoreHandle.respond_to? :new)
|
||||||
|
|
Loading…
Reference in a new issue