diff --git a/bin/domain/imag-notes/Cargo.toml b/bin/domain/imag-notes/Cargo.toml index 2d77b65f..9d4091e8 100644 --- a/bin/domain/imag-notes/Cargo.toml +++ b/bin/domain/imag-notes/Cargo.toml @@ -29,3 +29,4 @@ libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" libimagnotes = { version = "0.6.0", path = "../../../lib/domain/libimagnotes" } libimagentryedit = { version = "0.6.0", path = "../../../lib/entry/libimagentryedit" } libimagutil = { version = "0.6.0", path = "../../../lib/etc/libimagutil" } +libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } diff --git a/bin/domain/imag-notes/src/main.rs b/bin/domain/imag-notes/src/main.rs index d04208e6..35b38b0a 100644 --- a/bin/domain/imag-notes/src/main.rs +++ b/bin/domain/imag-notes/src/main.rs @@ -26,15 +26,21 @@ extern crate libimagrt; extern crate libimagentryedit; extern crate libimagerror; extern crate libimagutil; +extern crate libimagstore; + +use std::process::exit; use itertools::Itertools; use libimagentryedit::edit::Edit; use libimagrt::runtime::Runtime; use libimagrt::setup::generate_runtime_setup; +use libimagstore::iter::get::StoreIdGetIteratorExtension; use libimagnotes::note::Note; use libimagnotes::notestore::*; use libimagerror::trace::MapErrTrace; +use libimagerror::trace::trace_error_exit; +use libimagerror::iter::TraceIterator; use libimagutil::info_result::*; use libimagutil::warn_result::WarnResult; @@ -114,7 +120,12 @@ fn list(rt: &Runtime) { .store() .all_notes() .map_err_trace_exit_unwrap(1) - .filter_map(|noteid| rt.store().get(noteid).map_err_trace_exit_unwrap(1)) + .into_get_iter(rt.store()) + .unwrap_with(|e| trace_error_exit(&e, 1)) + .map(|opt| opt.unwrap_or_else(|| { + error!("Fatal: Nonexistent entry where entry should exist"); + exit(1) + })) .sorted_by(|note_a, note_b| if let (Ok(a), Ok(b)) = (note_a.get_name(), note_b.get_name()) { return a.cmp(&b) } else { diff --git a/lib/domain/libimagnotes/src/error.rs b/lib/domain/libimagnotes/src/error.rs index 6359edb2..fad31514 100644 --- a/lib/domain/libimagnotes/src/error.rs +++ b/lib/domain/libimagnotes/src/error.rs @@ -22,6 +22,10 @@ error_chain! { NoteError, NoteErrorKind, ResultExt, Result; } + foreign_links { + TomlQueryError(::toml_query::error::Error); + } + errors { StoreWriteError { description("Error writing store") diff --git a/lib/domain/libimagnotes/src/notestore.rs b/lib/domain/libimagnotes/src/notestore.rs index 0547b68a..2df2235b 100644 --- a/lib/domain/libimagnotes/src/notestore.rs +++ b/lib/domain/libimagnotes/src/notestore.rs @@ -17,15 +17,13 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use std::collections::BTreeMap; - use toml::Value; use libimagstore::storeid::IntoStoreId; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; -use toml_query::set::TomlValueSetExt; +use toml_query::insert::TomlValueInsertExt; use module_path::ModuleEntryPath; use error::Result; @@ -56,18 +54,7 @@ impl<'a> NoteStore<'a> for Store { { let entry = lockentry.deref_mut(); - - { - let header = entry.get_header_mut(); - let _ = header - .set("note", Value::Table(BTreeMap::new())) - .chain_err(|| NEK::StoreWriteError); - - let _ = header - .set("note.name", Value::String(name)) - .chain_err(|| NEK::StoreWriteError); - } - + entry.get_header_mut().insert("note.name", Value::String(name))?; *entry.get_content_mut() = text; }