From cebb85a7fe8376207dd97c6248587164610a30ca Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Wed, 8 Aug 2018 10:37:59 -0700 Subject: [PATCH] Pre: Move db/errors.rs into db_traits --- Cargo.toml | 3 +++ db-traits/Cargo.toml | 22 ++++++++++++++++++++++ {db/src => db-traits}/errors.rs | 0 db-traits/lib.rs | 20 ++++++++++++++++++++ db/Cargo.toml | 4 +++- db/src/bootstrap.rs | 2 +- db/src/cache.rs | 2 +- db/src/db.rs | 5 +++-- db/src/debug.rs | 2 +- db/src/internal_types.rs | 4 ++-- db/src/lib.rs | 7 ++----- db/src/metadata.rs | 2 +- db/src/schema.rs | 2 +- db/src/timelines.rs | 2 +- db/src/tx.rs | 4 ++-- db/src/tx_checking.rs | 2 +- db/src/tx_observer.rs | 2 +- db/src/types.rs | 2 +- db/src/upsert_resolution.rs | 2 +- db/src/watcher.rs | 2 +- query-projector/Cargo.toml | 3 +++ query-projector/src/errors.rs | 8 ++++---- query-projector/src/lib.rs | 1 + query-pull/Cargo.toml | 3 +++ query-pull/src/errors.rs | 2 +- query-pull/src/lib.rs | 1 + src/conn.rs | 8 ++++---- src/entity_builder.rs | 3 ++- src/errors.rs | 8 ++++---- src/lib.rs | 2 +- tolstoy/Cargo.toml | 3 +++ tolstoy/src/errors.rs | 8 ++++---- tolstoy/src/lib.rs | 1 + 33 files changed, 100 insertions(+), 42 deletions(-) create mode 100644 db-traits/Cargo.toml rename {db/src => db-traits}/errors.rs (100%) create mode 100644 db-traits/lib.rs diff --git a/Cargo.toml b/Cargo.toml index eb44ef5a..b15cbe67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,9 @@ path = "sql" [dependencies.mentat_db] path = "db" +[dependencies.db_traits] +path = "db-traits" + [dependencies.mentat_query] path = "query" diff --git a/db-traits/Cargo.toml b/db-traits/Cargo.toml new file mode 100644 index 00000000..9df1c5df --- /dev/null +++ b/db-traits/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "db_traits" +version = "0.0.1" +workspace = ".." + +[lib] +name = "db_traits" +path = "lib.rs" + +[dependencies] +failure = "0.1.1" +failure_derive = "0.1.1" + +[dependencies.edn] +path = "../edn" + +[dependencies.core_traits] +path = "../core-traits" + +[dependencies.rusqlite] +version = "0.13" +features = ["limits"] diff --git a/db/src/errors.rs b/db-traits/errors.rs similarity index 100% rename from db/src/errors.rs rename to db-traits/errors.rs diff --git a/db-traits/lib.rs b/db-traits/lib.rs new file mode 100644 index 00000000..3a05f1c2 --- /dev/null +++ b/db-traits/lib.rs @@ -0,0 +1,20 @@ +// Copyright 2018 Mozilla +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + + +extern crate failure; +#[macro_use] +extern crate failure_derive; +extern crate rusqlite; + +extern crate edn; +extern crate core_traits; + +pub mod errors; diff --git a/db/Cargo.toml b/db/Cargo.toml index 9fa88ed1..faaea93a 100644 --- a/db/Cargo.toml +++ b/db/Cargo.toml @@ -10,7 +10,6 @@ syncable = ["serde", "serde_json", "serde_derive"] [dependencies] failure = "0.1.1" -failure_derive = "0.1.1" indexmap = "1" itertools = "0.7" lazy_static = "0.2" @@ -35,6 +34,9 @@ path = "../core" [dependencies.core_traits] path = "../core-traits" +[dependencies.db_traits] +path = "../db-traits" + [dependencies.mentat_sql] path = "../sql" diff --git a/db/src/bootstrap.rs b/db/src/bootstrap.rs index 5b4b847e..d51ed16d 100644 --- a/db/src/bootstrap.rs +++ b/db/src/bootstrap.rs @@ -11,7 +11,7 @@ #![allow(dead_code)] use edn; -use errors::{ +use db_traits::errors::{ DbErrorKind, Result, }; diff --git a/db/src/cache.rs b/db/src/cache.rs index 7f7e7dc8..8809790f 100644 --- a/db/src/cache.rs +++ b/db/src/cache.rs @@ -110,7 +110,7 @@ use db::{ TypedSQLValue, }; -use errors::{ +use db_traits::errors::{ DbError, DbErrorKind, Result, diff --git a/db/src/db.rs b/db/src/db.rs index 20803b02..2df6e878 100644 --- a/db/src/db.rs +++ b/db/src/db.rs @@ -59,10 +59,11 @@ use mentat_core::{ ValueRc, }; -use errors::{ +use db_traits::errors::{ DbErrorKind, Result, }; + use metadata; use schema::{ SchemaBuilding, @@ -1237,7 +1238,7 @@ mod tests { use std::collections::{ BTreeMap, }; - use errors; + use db_traits::errors as errors; use internal_types::{ Term, }; diff --git a/db/src/debug.rs b/db/src/debug.rs index 8b755e90..6bb90685 100644 --- a/db/src/debug.rs +++ b/db/src/debug.rs @@ -65,7 +65,7 @@ use db::*; use db::{read_attribute_map,read_ident_map}; use edn; use entids; -use errors::Result; +use db_traits::errors::Result; use core_traits::{ Entid, diff --git a/db/src/internal_types.rs b/db/src/internal_types.rs index d6ac2641..12987380 100644 --- a/db/src/internal_types.rs +++ b/db/src/internal_types.rs @@ -41,8 +41,8 @@ use edn::entities::{ TxFunction, }; -use errors; -use errors::{ +use db_traits::errors as errors; +use db_traits::errors::{ DbErrorKind, Result, }; diff --git a/db/src/lib.rs b/db/src/lib.rs index fd52f1cd..b316ad15 100644 --- a/db/src/lib.rs +++ b/db/src/lib.rs @@ -9,7 +9,6 @@ // specific language governing permissions and limitations under the License. extern crate failure; -#[macro_use] extern crate failure_derive; extern crate indexmap; extern crate itertools; #[macro_use] extern crate lazy_static; @@ -25,6 +24,7 @@ extern crate time; #[macro_use] extern crate edn; #[macro_use] extern crate mentat_core; +#[macro_use] extern crate db_traits; extern crate core_traits; extern crate mentat_sql; @@ -32,13 +32,10 @@ use std::iter::repeat; use itertools::Itertools; -pub use errors::{ - DbError, +use db_traits::errors::{ DbErrorKind, Result, - SchemaConstraintViolation, }; -#[macro_use] pub mod errors; #[macro_use] pub mod debug; diff --git a/db/src/metadata.rs b/db/src/metadata.rs index cecdc27e..a24a5aae 100644 --- a/db/src/metadata.rs +++ b/db/src/metadata.rs @@ -34,7 +34,7 @@ use add_retract_alter_set::{ }; use edn::symbols; use entids; -use errors::{ +use db_traits::errors::{ DbErrorKind, Result, }; diff --git a/db/src/schema.rs b/db/src/schema.rs index 5e1a829a..c790609a 100644 --- a/db/src/schema.rs +++ b/db/src/schema.rs @@ -12,7 +12,7 @@ use db::TypedSQLValue; use edn; -use errors::{ +use db_traits::errors::{ DbErrorKind, Result, }; diff --git a/db/src/timelines.rs b/db/src/timelines.rs index ca00f633..935748a7 100644 --- a/db/src/timelines.rs +++ b/db/src/timelines.rs @@ -12,7 +12,7 @@ use std::ops::RangeFrom; use rusqlite; -use errors::{ +use db_traits::errors::{ DbErrorKind, Result, }; diff --git a/db/src/tx.rs b/db/src/tx.rs index d104cbb2..59d20a79 100644 --- a/db/src/tx.rs +++ b/db/src/tx.rs @@ -66,8 +66,8 @@ use edn::{ Keyword, }; use entids; -use errors; -use errors::{ +use db_traits::errors as errors; +use db_traits::errors::{ DbErrorKind, Result, }; diff --git a/db/src/tx_checking.rs b/db/src/tx_checking.rs index 56a51a6a..d078a2e6 100644 --- a/db/src/tx_checking.rs +++ b/db/src/tx_checking.rs @@ -19,7 +19,7 @@ use core_traits::{ ValueType, }; -use errors::{ +use db_traits::errors::{ CardinalityConflict, }; diff --git a/db/src/tx_observer.rs b/db/src/tx_observer.rs index f65478d8..cc1bf9f0 100644 --- a/db/src/tx_observer.rs +++ b/db/src/tx_observer.rs @@ -39,7 +39,7 @@ use edn::entities::{ OpType, }; -use errors::{ +use db_traits::errors::{ Result, }; diff --git a/db/src/types.rs b/db/src/types.rs index b87d86c4..0219e709 100644 --- a/db/src/types.rs +++ b/db/src/types.rs @@ -45,7 +45,7 @@ use edn::entities::{ TempId, }; -use errors; +use db_traits::errors as errors; /// Represents one partition of the entid space. #[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)] diff --git a/db/src/upsert_resolution.rs b/db/src/upsert_resolution.rs index 55576c56..b2a58798 100644 --- a/db/src/upsert_resolution.rs +++ b/db/src/upsert_resolution.rs @@ -21,7 +21,7 @@ use std::collections::{ use indexmap; use petgraph::unionfind; -use errors::{ +use db_traits::errors::{ DbErrorKind, Result, }; diff --git a/db/src/watcher.rs b/db/src/watcher.rs index 8a8c628a..62c535ae 100644 --- a/db/src/watcher.rs +++ b/db/src/watcher.rs @@ -30,7 +30,7 @@ use edn::entities::{ OpType, }; -use errors::{ +use db_traits::errors::{ Result, }; diff --git a/query-projector/Cargo.toml b/query-projector/Cargo.toml index 7be36be2..4a4daa9e 100644 --- a/query-projector/Cargo.toml +++ b/query-projector/Cargo.toml @@ -21,6 +21,9 @@ path = "../core" [dependencies.mentat_db] path = "../db" +[dependencies.db_traits] +path = "../db-traits" + [dependencies.mentat_sql] path = "../sql" diff --git a/query-projector/src/errors.rs b/query-projector/src/errors.rs index 040a6f63..b86c22df 100644 --- a/query-projector/src/errors.rs +++ b/query-projector/src/errors.rs @@ -15,7 +15,7 @@ use rusqlite; use mentat_core::{ ValueTypeSet, }; -use mentat_db; +use db_traits::errors::DbError; use mentat_query::{ PlainSymbol, }; @@ -71,7 +71,7 @@ pub enum ProjectorError { RusqliteError(String), #[fail(display = "{}", _0)] - DbError(#[cause] mentat_db::DbError), + DbError(#[cause] DbError), #[fail(display = "{}", _0)] PullError(#[cause] mentat_query_pull::PullError), @@ -83,8 +83,8 @@ impl From for ProjectorError { } } -impl From for ProjectorError { - fn from(error: mentat_db::DbError) -> ProjectorError { +impl From for ProjectorError { + fn from(error: DbError) -> ProjectorError { ProjectorError::DbError(error) } } diff --git a/query-projector/src/lib.rs b/query-projector/src/lib.rs index da6f28de..d4538aca 100644 --- a/query-projector/src/lib.rs +++ b/query-projector/src/lib.rs @@ -16,6 +16,7 @@ extern crate indexmap; extern crate rusqlite; extern crate mentat_core; +extern crate db_traits; extern crate core_traits; extern crate mentat_db; // For value conversion. extern crate mentat_query; diff --git a/query-pull/Cargo.toml b/query-pull/Cargo.toml index 6c037461..238acd68 100644 --- a/query-pull/Cargo.toml +++ b/query-pull/Cargo.toml @@ -20,6 +20,9 @@ path = "../core-traits" [dependencies.mentat_db] path = "../db" +[dependencies.db_traits] +path = "../db-traits" + [dependencies.mentat_query] path = "../query" diff --git a/query-pull/src/errors.rs b/query-pull/src/errors.rs index 3705d269..bef70eec 100644 --- a/query-pull/src/errors.rs +++ b/query-pull/src/errors.rs @@ -10,7 +10,7 @@ use std; // To refer to std::result::Result. -use mentat_db::{ +use db_traits::errors::{ DbError, }; diff --git a/query-pull/src/lib.rs b/query-pull/src/lib.rs index 7398b8ef..1622292c 100644 --- a/query-pull/src/lib.rs +++ b/query-pull/src/lib.rs @@ -67,6 +67,7 @@ extern crate rusqlite; extern crate mentat_core; extern crate core_traits; extern crate mentat_db; +extern crate db_traits; extern crate mentat_query; extern crate mentat_query_algebrizer; extern crate mentat_query_sql; diff --git a/src/conn.rs b/src/conn.rs index 86f49bb3..9caff173 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -562,7 +562,7 @@ impl<'a, 'o> TransactWatcher for InProgressTransactWatcher<'a, 'o> { self.observer_watcher.datom(op.clone(), e.clone(), a.clone(), v); } - fn done(&mut self, t: &Entid, schema: &Schema) -> ::mentat_db::errors::Result<()> { + fn done(&mut self, t: &Entid, schema: &Schema) -> ::db_traits::errors::Result<()> { self.cache_watcher.done(t, schema)?; self.observer_watcher.done(t, schema)?; self.tx_id = Some(t.clone()); @@ -895,7 +895,7 @@ mod tests { match conn.transact(&mut sqlite, t.as_str()) { Err(MentatError::DbError(e)) => { - assert_eq!(e.kind(), ::mentat_db::DbErrorKind::UnrecognizedEntid(next + 1)); + assert_eq!(e.kind(), ::db_traits::errors::DbErrorKind::UnrecognizedEntid(next + 1)); }, x => panic!("expected db error, got {:?}", x), } @@ -923,7 +923,7 @@ mod tests { match conn.transact(&mut sqlite, t.as_str()) { Err(MentatError::DbError(e)) => { // All this, despite this being the ID we were about to allocate! - assert_eq!(e.kind(), ::mentat_db::DbErrorKind::UnrecognizedEntid(next)); + assert_eq!(e.kind(), ::db_traits::errors::DbErrorKind::UnrecognizedEntid(next)); }, x => panic!("expected db error, got {:?}", x), } @@ -1107,7 +1107,7 @@ mod tests { match report.expect_err("expected transact error") { MentatError::DbError(e) => { match e.kind() { - ::mentat_db::DbErrorKind::SchemaConstraintViolation(_) => {}, + ::db_traits::errors::DbErrorKind::SchemaConstraintViolation(_) => {}, _ => panic!("expected SchemaConstraintViolation"), } }, diff --git a/src/entity_builder.rs b/src/entity_builder.rs index 6aa0d0f9..64005247 100644 --- a/src/entity_builder.rs +++ b/src/entity_builder.rs @@ -282,6 +282,7 @@ impl<'a, 'c> EntityBuilder> { #[cfg(test)] mod testing { extern crate mentat_db; + extern crate db_traits; use ::{ Conn, @@ -326,7 +327,7 @@ mod testing { // This should fail: unrecognized entid. match in_progress.transact_entities(terms).expect_err("expected transact to fail") { MentatError::DbError(e) => { - assert_eq!(e.kind(), mentat_db::DbErrorKind::UnrecognizedEntid(999)); + assert_eq!(e.kind(), db_traits::errors::DbErrorKind::UnrecognizedEntid(999)); }, _ => panic!("Should have rejected the entid."), } diff --git a/src/errors.rs b/src/errors.rs index eb14341e..23bc9549 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -26,7 +26,7 @@ use mentat_core::{ Attribute, }; -use mentat_db; +use db_traits::errors::DbError; use mentat_query; use mentat_query_algebrizer; use mentat_query_projector; @@ -98,7 +98,7 @@ pub enum MentatError { EdnParseError(#[cause] edn::ParseError), #[fail(display = "{}", _0)] - DbError(#[cause] mentat_db::DbError), + DbError(#[cause] DbError), #[fail(display = "{}", _0)] AlgebrizerError(#[cause] mentat_query_algebrizer::AlgebrizerError), @@ -135,8 +135,8 @@ impl From for MentatError { } } -impl From for MentatError { - fn from(error: mentat_db::DbError) -> MentatError { +impl From for MentatError { + fn from(error: DbError) -> MentatError { MentatError::DbError(error) } } diff --git a/src/lib.rs b/src/lib.rs index 1cd9d336..51d4adfd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ pub extern crate edn; extern crate mentat_core; extern crate core_traits; extern crate mentat_db; +extern crate db_traits; extern crate mentat_query; extern crate mentat_query_algebrizer; extern crate mentat_query_projector; @@ -138,7 +139,6 @@ pub use edn::{ ToMicros, ToMillis, }; -pub use mentat_db::DbError; pub use mentat_query_algebrizer::AlgebrizerError; pub use mentat_query_projector::{ BindingTuple, diff --git a/tolstoy/Cargo.toml b/tolstoy/Cargo.toml index 7741ddcc..d5c4a314 100644 --- a/tolstoy/Cargo.toml +++ b/tolstoy/Cargo.toml @@ -30,6 +30,9 @@ path = "../core-traits" [dependencies.mentat_db] path = "../db" +[dependencies.db_traits] +path = "../db-traits" + [dependencies.rusqlite] version = "0.13" features = ["limits"] diff --git a/tolstoy/src/errors.rs b/tolstoy/src/errors.rs index a44a89e8..82c2a0b2 100644 --- a/tolstoy/src/errors.rs +++ b/tolstoy/src/errors.rs @@ -14,7 +14,7 @@ use uuid; use hyper; use serde_json; -use mentat_db; +use db_traits::errors::DbError; #[macro_export] macro_rules! bail { @@ -46,7 +46,7 @@ pub enum TolstoyError { NotYetImplemented(String), #[fail(display = "{}", _0)] - DbError(#[cause] mentat_db::DbError), + DbError(#[cause] DbError), #[fail(display = "{}", _0)] SerializationError(#[cause] serde_json::Error), @@ -69,8 +69,8 @@ pub enum TolstoyError { UriError(#[cause] hyper::error::UriError), } -impl From for TolstoyError { - fn from(error: mentat_db::DbError) -> TolstoyError { +impl From for TolstoyError { + fn from(error: DbError) -> TolstoyError { TolstoyError::DbError(error) } } diff --git a/tolstoy/src/lib.rs b/tolstoy/src/lib.rs index 0565c7bc..7ff9fd08 100644 --- a/tolstoy/src/lib.rs +++ b/tolstoy/src/lib.rs @@ -34,6 +34,7 @@ extern crate serde_json; #[cfg_attr(test, macro_use)] extern crate mentat_db; extern crate mentat_core; +extern crate db_traits; extern crate core_traits; extern crate rusqlite; extern crate uuid;