diff --git a/lib/Cargo.toml b/lib/Cargo.toml index f1bd08ef..c402bf10 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -20,7 +20,7 @@ md-5 = "0.8" sha-1 = "0.8" sha2 = "0.8" digest = "0.8" -failure = "0.1" +anyhow = "1" regex = "1" rio_api = "0.4" rio_turtle = "0.4" diff --git a/lib/benches/sparql_query.rs b/lib/benches/sparql_query.rs index ef7ffc09..15f83821 100644 --- a/lib/benches/sparql_query.rs +++ b/lib/benches/sparql_query.rs @@ -1,5 +1,5 @@ +use anyhow::anyhow; use criterion::{criterion_group, criterion_main, Criterion}; -use failure::format_err; use oxigraph::model::vocab::rdf; use oxigraph::model::*; use oxigraph::sparql::*; @@ -55,7 +55,7 @@ fn to_relative_path(url: &str) -> Result { "rdf-tests/sparql11/", )) } else { - Err(format_err!("Not supported url for file: {}", url)) + Err(anyhow!("Not supported url for file: {}", url)) } } @@ -65,7 +65,7 @@ fn read_file(url: &str) -> Result { base_path.push(to_relative_path(url)?); Ok(BufReader::new(File::open(&base_path).map_err(|e| { - format_err!("Opening file {} failed with {}", base_path.display(), e) + anyhow!("Opening file {} failed with {}", base_path.display(), e) })?)) } @@ -98,7 +98,7 @@ fn load_graph_to_repository( } else if url.ends_with(".rdf") { GraphSyntax::RdfXml } else { - return Err(format_err!("Serialization type not found for {}", url)); + return Err(anyhow!("Serialization type not found for {}", url)); }; connection.load_graph(read_file(url)?, syntax, to_graph_name, Some(url)) } @@ -214,21 +214,18 @@ impl Iterator for TestManifest { let n = n.clone().into(); match self.graph.object_for_subject_predicate(&n, &qt::QUERY) { Some(Term::NamedNode(q)) => q.as_str().to_owned(), - Some(_) => return Some(Err(format_err!("invalid query"))), - None => return Some(Err(format_err!("query not found"))), + Some(_) => return Some(Err(anyhow!("invalid query"))), + None => return Some(Err(anyhow!("query not found"))), } } - Some(_) => return Some(Err(format_err!("invalid action"))), + Some(_) => return Some(Err(anyhow!("invalid action"))), None => { - return Some(Err(format_err!( - "action not found for test {}", - test_subject - ))); + return Some(Err(anyhow!("action not found for test {}", test_subject))); } }; Some(Ok(Test { kind, query })) } - Some(_) => Some(Err(format_err!("invalid test list"))), + Some(_) => Some(Err(anyhow!("invalid test list"))), None => { match self.manifests_to_do.pop() { Some(url) => { @@ -253,7 +250,7 @@ impl Iterator for TestManifest { }), ); } - Some(_) => return Some(Err(format_err!("invalid tests list"))), + Some(_) => return Some(Err(anyhow!("invalid tests list"))), None => (), } @@ -269,10 +266,7 @@ impl Iterator for TestManifest { )); } Some(term) => { - return Some(Err(format_err!( - "Invalid tests list. Got term {}", - term - ))); + return Some(Err(anyhow!("Invalid tests list. Got term {}", term))); } None => (), } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index d953721a..c63e6391 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -109,7 +109,7 @@ pub mod sparql; pub(crate) mod store; mod syntax; -pub use failure::Error; +pub use anyhow::Error; pub type Result = ::std::result::Result; pub use crate::repository::Repository; pub use crate::repository::RepositoryConnection; diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index 64313c29..349ba59e 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -8,8 +8,8 @@ use crate::sparql::ServiceHandler; use crate::store::numeric_encoder::*; use crate::store::StoreConnection; use crate::Result; +use anyhow::anyhow; use digest::Digest; -use failure::format_err; use md5::Md5; use rand::random; use regex::{Regex, RegexBuilder}; @@ -220,7 +220,7 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator { if let Some(graph_name) = get_pattern_value(graph_name, &tuple) { graph_name } else { - let result: EncodedTuplesIterator<'_> = Box::new(once(Err(format_err!( + let result: EncodedTuplesIterator<'_> = Box::new(once(Err(anyhow!( "Unknown graph name is not allowed when evaluating property path" )))); return result; @@ -493,7 +493,7 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator { ) -> Result> { let service_name = self.dataset.decode_named_node( get_pattern_value(service_name, from) - .ok_or_else(|| format_err!("The SERVICE name is not bound"))?, + .ok_or_else(|| anyhow!("The SERVICE name is not bound"))?, )?; Ok(self.encode_bindings( variables, diff --git a/lib/src/sparql/json_results.rs b/lib/src/sparql/json_results.rs index 7ee607d6..cb1e76db 100644 --- a/lib/src/sparql/json_results.rs +++ b/lib/src/sparql/json_results.rs @@ -3,7 +3,7 @@ use crate::model::*; use crate::sparql::model::*; use crate::Result; -use failure::format_err; +use anyhow::anyhow; use std::io::Write; pub fn write_json_results(results: QueryResult<'_>, mut sink: W) -> Result { @@ -79,7 +79,7 @@ pub fn write_json_results(results: QueryResult<'_>, mut sink: W) -> Re sink.write_all(b"]}}")?; } QueryResult::Graph(_) => { - return Err(format_err!( + return Err(anyhow!( "Graphs could not be formatted to SPARQL query results XML format" )); } diff --git a/lib/src/sparql/mod.rs b/lib/src/sparql/mod.rs index ffcacb87..99152065 100644 --- a/lib/src/sparql/mod.rs +++ b/lib/src/sparql/mod.rs @@ -18,7 +18,7 @@ use crate::sparql::plan::{DatasetView, PlanNode}; use crate::sparql::plan_builder::PlanBuilder; use crate::store::StoreConnection; use crate::Result; -use failure::format_err; +use anyhow::anyhow; use rio_api::iri::Iri; use std::fmt; @@ -180,7 +180,7 @@ struct EmptyServiceHandler; impl ServiceHandler for EmptyServiceHandler { fn handle<'a>(&'a self, _: &NamedNode, _: &'a GraphPattern) -> Result> { - Err(format_err!("The SERVICE feature is not implemented")) + Err(anyhow!("The SERVICE feature is not implemented")) } } diff --git a/lib/src/sparql/model.rs b/lib/src/sparql/model.rs index d38f0f39..0a36c4ba 100644 --- a/lib/src/sparql/model.rs +++ b/lib/src/sparql/model.rs @@ -2,7 +2,7 @@ use crate::model::*; use crate::sparql::json_results::write_json_results; use crate::sparql::xml_results::{read_xml_results, write_xml_results}; use crate::{FileSyntax, GraphSyntax, Result}; -use failure::format_err; +use anyhow::anyhow; use rand::random; use rio_api::formatter::TriplesFormatter; use rio_turtle::{NTriplesFormatter, TurtleFormatter}; @@ -61,7 +61,7 @@ impl<'a> QueryResult<'a> { } }) } else { - Err(format_err!( + Err(anyhow!( "Bindings or booleans could not be formatted as an RDF graph" )) } @@ -168,7 +168,7 @@ impl Variable { pub fn name(&self) -> Result<&str> { match self { Variable::Variable { name } => Ok(name), - _ => Err(format_err!("The variable {} has no name", self)), + _ => Err(anyhow!("The variable {} has no name", self)), } } } diff --git a/lib/src/sparql/plan_builder.rs b/lib/src/sparql/plan_builder.rs index 33513b47..de2bfb21 100644 --- a/lib/src/sparql/plan_builder.rs +++ b/lib/src/sparql/plan_builder.rs @@ -6,7 +6,7 @@ use crate::sparql::plan::PlanPropertyPath; use crate::sparql::plan::*; use crate::store::numeric_encoder::{Encoder, ENCODED_DEFAULT_GRAPH}; use crate::Result; -use failure::format_err; +use anyhow::anyhow; use std::collections::HashSet; pub struct PlanBuilder { @@ -654,7 +654,7 @@ impl PlanBuilder { "string", )? } else { - return Err(format_err!("Not supported custom function {}", expression)); + return Err(anyhow!("Not supported custom function {}", expression)); } } }, @@ -680,10 +680,7 @@ impl PlanBuilder { graph_name, )?))) } else { - Err(format_err!( - "The xsd:{} casting takes only one parameter", - name - )) + Err(anyhow!("The xsd:{} casting takes only one parameter", name)) } } diff --git a/lib/src/sparql/xml_results.rs b/lib/src/sparql/xml_results.rs index e2ea83a5..bf1f1d0d 100644 --- a/lib/src/sparql/xml_results.rs +++ b/lib/src/sparql/xml_results.rs @@ -3,7 +3,7 @@ use crate::model::*; use crate::sparql::model::*; use crate::Result; -use failure::format_err; +use anyhow::anyhow; use quick_xml::events::BytesDecl; use quick_xml::events::BytesEnd; use quick_xml::events::BytesStart; @@ -99,7 +99,7 @@ pub fn write_xml_results(results: QueryResult<'_>, sink: W) -> Result< writer.write_event(Event::End(BytesEnd::borrowed(b"sparql")))?; } QueryResult::Graph(_) => { - return Err(format_err!( + return Err(anyhow!( "Graphs could not be formatted to SPARQL query results XML format" )); } @@ -130,7 +130,7 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result let (ns, event) = reader.read_namespaced_event(&mut buffer, &mut namespace_buffer)?; if let Some(ns) = ns { if ns != b"http://www.w3.org/2005/sparql-results#".as_ref() { - return Err(format_err!( + return Err(anyhow!( "Unexpected namespace found in RDF/XML query result: {}", reader.decode(ns)? )); @@ -144,14 +144,14 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result if event.name() == b"sparql" { state = State::Sparql; } else { - return Err(format_err!("Expecting tag, found {}", reader.decode(event.name())?)); + return Err(anyhow!("Expecting tag, found {}", reader.decode(event.name())?)); } } State::Sparql => { if event.name() == b"head" { state = State::Head; } else { - return Err(format_err!("Expecting tag, found {}", reader.decode(event.name())?)); + return Err(anyhow!("Expecting tag, found {}", reader.decode(event.name())?)); } } State::Head => { @@ -159,12 +159,12 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result let name = event.attributes() .filter_map(|attr| attr.ok()) .find(|attr| attr.key == b"name") - .ok_or_else(|| format_err!("No name attribute found for the tag"))?; + .ok_or_else(|| anyhow!("No name attribute found for the tag"))?; variables.push(name.unescape_and_decode_value(&reader)?); } else if event.name() == b"link" { // no op } else { - return Err(format_err!("Expecting or tag, found {}", reader.decode(event.name())?)); + return Err(anyhow!("Expecting or tag, found {}", reader.decode(event.name())?)); } } State::AfterHead => { @@ -186,17 +186,17 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result }), ))); } else if event.name() != b"link" && event.name() != b"results" && event.name() != b"boolean" { - return Err(format_err!("Expecting sparql tag, found {}", reader.decode(event.name())?)); + return Err(anyhow!("Expecting sparql tag, found {}", reader.decode(event.name())?)); } } - State::Boolean => return Err(format_err!("Unexpected tag inside of tag: {}", reader.decode(event.name())?)) + State::Boolean => return Err(anyhow!("Unexpected tag inside of tag: {}", reader.decode(event.name())?)) }, Event::Empty(event) => match state { State::Sparql => { if event.name() == b"head" { state = State::AfterHead; } else { - return Err(format_err!("Expecting tag, found {}", reader.decode(event.name())?)); + return Err(anyhow!("Expecting tag, found {}", reader.decode(event.name())?)); } } State::Head => { @@ -204,12 +204,12 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result let name = event.attributes() .filter_map(|v| v.ok()) .find(|attr| attr.key == b"name") - .ok_or_else(|| format_err!("No name attribute found for the tag"))?; + .ok_or_else(|| anyhow!("No name attribute found for the tag"))?; variables.push(name.unescape_and_decode_value(&reader)?); } else if event.name() == b"link" { // no op } else { - return Err(format_err!("Expecting or tag, found {}", reader.decode(event.name())?)); + return Err(anyhow!("Expecting or tag, found {}", reader.decode(event.name())?)); } }, State::AfterHead => { @@ -219,10 +219,10 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result Box::new(empty()), ))) } else { - return Err(format_err!("Unexpected autoclosing tag <{}>", reader.decode(event.name())?)) + return Err(anyhow!("Unexpected autoclosing tag <{}>", reader.decode(event.name())?)) } } - _ => return Err(format_err!("Unexpected autoclosing tag <{}>", reader.decode(event.name())?)) + _ => return Err(anyhow!("Unexpected autoclosing tag <{}>", reader.decode(event.name())?)) }, Event::Text(event) => { let value = event.unescaped()?; @@ -233,18 +233,18 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result } else if value.as_ref() == b"false" { Ok(QueryResult::Boolean(false)) } else { - Err(format_err!("Unexpected boolean value. Found {}", reader.decode(&value)?)) + Err(anyhow!("Unexpected boolean value. Found {}", reader.decode(&value)?)) }; } - _ => Err(format_err!("Unexpected textual value found: {}", reader.decode(&value)?)) + _ => Err(anyhow!("Unexpected textual value found: {}", reader.decode(&value)?)) }; }, Event::End(_) => if let State::Head = state { state = State::AfterHead; } else { - return Err(format_err!("Unexpected early file end. All results file should have a and a or tag")); + return Err(anyhow!("Unexpected early file end. All results file should have a and a or tag")); }, - Event::Eof => return Err(format_err!("Unexpected early file end. All results file should have a and a or tag")), + Event::Eof => return Err(anyhow!("Unexpected early file end. All results file should have a and a or tag")), _ => (), } } @@ -292,7 +292,7 @@ impl ResultsIterator { .read_namespaced_event(&mut self.buffer, &mut self.namespace_buffer)?; if let Some(ns) = ns { if ns != b"http://www.w3.org/2005/sparql-results#".as_ref() { - return Err(format_err!( + return Err(anyhow!( "Unexpected namespace found in RDF/XML query result: {}", self.reader.decode(ns)? )); @@ -304,7 +304,7 @@ impl ResultsIterator { if event.name() == b"result" { state = State::Result; } else { - return Err(format_err!( + return Err(anyhow!( "Expecting , found {}", self.reader.decode(event.name())? )); @@ -319,14 +319,14 @@ impl ResultsIterator { { Some(attr) => current_var = Some(attr.unescaped_value()?.to_vec()), None => { - return Err(format_err!( + return Err(anyhow!( "No name attribute found for the tag" )); } } state = State::Binding; } else { - return Err(format_err!( + return Err(anyhow!( "Expecting , found {}", self.reader.decode(event.name())? )); @@ -334,7 +334,7 @@ impl ResultsIterator { } State::Binding => { if term.is_some() { - return Err(format_err!( + return Err(anyhow!( "There is already a value for the current binding" )); } @@ -356,7 +356,7 @@ impl ResultsIterator { } state = State::Literal; } else { - return Err(format_err!( + return Err(anyhow!( "Expecting , or found {}", self.reader.decode(event.name())? )); @@ -390,7 +390,7 @@ impl ResultsIterator { ); } _ => { - return Err(format_err!( + return Err(anyhow!( "Unexpected textual value found: {}", self.reader.decode(&data)? )); @@ -404,7 +404,7 @@ impl ResultsIterator { if let Some(var) = ¤t_var { new_bindings[self.mapping[var]] = term.clone() } else { - return Err(format_err!("No name found for tag")); + return Err(anyhow!("No name found for tag")); } term = None; state = State::Result; diff --git a/lib/src/store/memory.rs b/lib/src/store/memory.rs index f02622b2..59c3b0d1 100644 --- a/lib/src/store/memory.rs +++ b/lib/src/store/memory.rs @@ -1,8 +1,9 @@ use crate::store::numeric_encoder::*; use crate::store::*; use crate::{Repository, Result}; -use failure::{Backtrace, Fail}; use std::collections::{HashMap, HashSet}; +use std::error::Error; +use std::fmt; use std::hash::Hash; use std::iter::{empty, once}; use std::sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard}; @@ -681,16 +682,19 @@ impl StoreTransaction for MemoryTransaction<'_> { } } -#[derive(Debug, Fail)] -#[fail(display = "Mutex Mutex was poisoned")] -pub struct MutexPoisonError { - backtrace: Backtrace, +#[derive(Debug)] +struct MutexPoisonError {} + +impl fmt::Display for MutexPoisonError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "Mutex was poisoned") + } } +impl Error for MutexPoisonError {} + impl From> for MutexPoisonError { fn from(_: PoisonError) -> Self { - Self { - backtrace: Backtrace::new(), - } + Self {} } } diff --git a/lib/src/store/numeric_encoder.rs b/lib/src/store/numeric_encoder.rs index cea44f2f..d489b4b5 100644 --- a/lib/src/store/numeric_encoder.rs +++ b/lib/src/store/numeric_encoder.rs @@ -3,7 +3,7 @@ use crate::model::vocab::xsd; use crate::model::xsd::*; use crate::model::*; use crate::Result; -use failure::format_err; +use anyhow::anyhow; use md5::digest::Digest; use md5::Md5; use rand::random; @@ -604,7 +604,7 @@ impl TermReader for R { buffer, ))) } - _ => Err(format_err!("the term buffer has an invalid type id")), + _ => Err(anyhow!("the term buffer has an invalid type id")), } } @@ -1106,21 +1106,17 @@ pub trait Decoder { match self.decode_term(encoded)? { Term::NamedNode(named_node) => Ok(named_node.into()), Term::BlankNode(blank_node) => Ok(blank_node.into()), - Term::Literal(_) => Err(format_err!( - "A literal has ben found instead of a named node" - )), + Term::Literal(_) => Err(anyhow!("A literal has ben found instead of a named node")), } } fn decode_named_node(&self, encoded: EncodedTerm) -> Result { match self.decode_term(encoded)? { Term::NamedNode(named_node) => Ok(named_node), - Term::BlankNode(_) => Err(format_err!( + Term::BlankNode(_) => Err(anyhow!( "A blank node has been found instead of a named node" )), - Term::Literal(_) => Err(format_err!( - "A literal has ben found instead of a named node" - )), + Term::Literal(_) => Err(anyhow!("A literal has ben found instead of a named node")), } } @@ -1148,9 +1144,7 @@ pub trait Decoder { impl Decoder for S { fn decode_term(&self, encoded: EncodedTerm) -> Result { match encoded { - EncodedTerm::DefaultGraph => { - Err(format_err!("The default graph tag is not a valid term")) - } + EncodedTerm::DefaultGraph => Err(anyhow!("The default graph tag is not a valid term")), EncodedTerm::NamedNode { iri_id } => { Ok(NamedNode::new_unchecked(get_required_str(self, iri_id)?).into()) } @@ -1189,7 +1183,7 @@ impl Decoder for S { fn get_required_str(lookup: &impl StrLookup, id: u128) -> Result { lookup.get_str(id)?.ok_or_else(|| { - format_err!( + anyhow!( "Not able to find the string with id {} in the string store", id ) diff --git a/lib/src/store/rocksdb.rs b/lib/src/store/rocksdb.rs index c2e166d4..d65e132f 100644 --- a/lib/src/store/rocksdb.rs +++ b/lib/src/store/rocksdb.rs @@ -1,7 +1,7 @@ use crate::store::numeric_encoder::*; use crate::store::{Store, StoreConnection, StoreRepositoryConnection, StoreTransaction}; use crate::{Repository, Result}; -use failure::format_err; +use anyhow::anyhow; use rocksdb::*; use std::io::Cursor; use std::iter::{empty, once}; @@ -596,7 +596,7 @@ impl RocksDbStoreInnerTransaction<'_> { fn get_cf<'a>(db: &'a DB, name: &str) -> Result<&'a ColumnFamily> { db.cf_handle(name) - .ok_or_else(|| format_err!("column family {} not found", name)) + .ok_or_else(|| anyhow!("column family {} not found", name)) } fn wrap_error<'a, E: 'a, I: Iterator> + 'a>( diff --git a/lib/tests/service_test_cases.rs b/lib/tests/service_test_cases.rs index 6f7d197b..5028f7aa 100644 --- a/lib/tests/service_test_cases.rs +++ b/lib/tests/service_test_cases.rs @@ -1,4 +1,4 @@ -use failure::format_err; +use anyhow::anyhow; use oxigraph::model::*; use oxigraph::sparql::{ BindingsIterator, GraphPattern, PreparedQuery, QueryOptions, QueryResult, ServiceHandler, @@ -73,7 +73,7 @@ fn two_service_test() { .as_ref(); do_pattern(triples, graph_pattern, QueryOptions::default()) } else { - Err(format_err!("not found")) + Err(anyhow!("not found")) } } } @@ -124,7 +124,7 @@ fn silent_service_empty_set_test() { _: &NamedNode, _: &'a GraphPattern, ) -> Result> { - Err(format_err!("This is supposed to fail")) + Err(anyhow!("This is supposed to fail")) } } @@ -162,7 +162,7 @@ fn non_silent_service_test() { _: &NamedNode, _: &'a GraphPattern, ) -> Result> { - Err(format_err!("This is supposed to fail")) + Err(anyhow!("This is supposed to fail")) } } @@ -232,9 +232,7 @@ fn query_repository<'a>( Box::new(collected.into_iter()), )) } - _ => Err(format_err!( - "Excpected bindings but got another QueryResult" - )), + _ => Err(anyhow!("Excpected bindings but got another QueryResult")), } } @@ -256,7 +254,7 @@ fn pattern_repository<'a>( Box::new(collected.into_iter()), )) } - _ => Err(format_err!("Expected bindings but got another QueryResult")), + _ => Err(anyhow!("Expected bindings but got another QueryResult")), } } diff --git a/lib/tests/sparql_test_cases.rs b/lib/tests/sparql_test_cases.rs index cb05dccf..e2fb911c 100644 --- a/lib/tests/sparql_test_cases.rs +++ b/lib/tests/sparql_test_cases.rs @@ -1,5 +1,5 @@ ///! Integration tests based on [SPARQL 1.1 Test Cases](https://www.w3.org/2009/sparql/docs/tests/README.html) -use failure::format_err; +use anyhow::anyhow; use oxigraph::model::vocab::rdf; use oxigraph::model::vocab::rdfs; use oxigraph::model::*; @@ -162,27 +162,27 @@ fn sparql_w3c_query_evaluation_testsuite() -> Result<()> { .connection()? .prepare_query(&read_file_to_string(&test.query)?, QueryOptions::default().with_base_iri(&test.query).with_service_handler(StaticServiceHandler::new(&test.service_data)?)) { - Err(error) => Err(format_err!( + Err(error) => Err(anyhow!( "Failure to parse query of {} with error: {}", test, error )), Ok(query) => match query.exec() { - Err(error) => Err(format_err!( + Err(error) => Err(anyhow!( "Failure to execute query of {} with error: {}", test, error )), Ok(result) => { let expected_graph = - load_sparql_query_result_graph(test.result.as_ref().unwrap()).map_err(|e| format_err!("Error constructing expected graph for {}: {}", test, e))?; + load_sparql_query_result_graph(test.result.as_ref().unwrap()).map_err(|e| anyhow!("Error constructing expected graph for {}: {}", test, e))?; let with_order = expected_graph .triples_for_predicate(&rs::INDEX) .next() .is_some(); - let actual_graph = to_graph(result, with_order).map_err(|e| format_err!("Error constructing result graph for {}: {}", test, e))?; + let actual_graph = to_graph(result, with_order).map_err(|e| anyhow!("Error constructing result graph for {}: {}", test, e))?; if actual_graph.is_isomorphic(&expected_graph) { Ok(()) } else { - Err(format_err!("Failure on {}.\nExpected file:\n{}\nOutput file:\n{}\nParsed query:\n{}\nData:\n{}\n", + Err(anyhow!("Failure on {}.\nExpected file:\n{}\nOutput file:\n{}\nParsed query:\n{}\nData:\n{}\n", test, expected_graph, actual_graph, @@ -240,7 +240,7 @@ fn load_graph_to_repository( } else if url.ends_with(".rdf") { GraphSyntax::RdfXml } else { - return Err(format_err!("Serialization type not found for {}", url)); + return Err(anyhow!("Serialization type not found for {}", url)); }; connection.load_graph(read_file(url)?, syntax, to_graph_name, Some(url)) } @@ -276,7 +276,7 @@ fn to_relative_path(url: &str) -> Result { "rdf-tests/sparql11/", )) } else { - Err(format_err!("Not supported url for file: {}", url)) + Err(anyhow!("Not supported url for file: {}", url)) } } @@ -286,7 +286,7 @@ fn read_file(url: &str) -> Result { base_path.push(to_relative_path(url)?); Ok(BufReader::new(File::open(&base_path).map_err(|e| { - format_err!("Opening file {} failed with {}", base_path.display(), e) + anyhow!("Opening file {} failed with {}", base_path.display(), e) })?)) } @@ -528,8 +528,8 @@ impl Iterator for TestManifest { let n = n.clone().into(); let query = match self.graph.object_for_subject_predicate(&n, &qt::QUERY) { Some(Term::NamedNode(q)) => q.as_str().to_owned(), - Some(_) => return Some(Err(format_err!("invalid query"))), - None => return Some(Err(format_err!("query not found"))), + Some(_) => return Some(Err(anyhow!("invalid query"))), + None => return Some(Err(anyhow!("query not found"))), }; let data = match self.graph.object_for_subject_predicate(&n, &qt::DATA) { Some(Term::NamedNode(q)) => Some(q.as_str().to_owned()), @@ -567,12 +567,9 @@ impl Iterator for TestManifest { .collect(); (query, data, graph_data, service_data) } - Some(_) => return Some(Err(format_err!("invalid action"))), + Some(_) => return Some(Err(anyhow!("invalid action"))), None => { - return Some(Err(format_err!( - "action not found for test {}", - test_subject - ))); + return Some(Err(anyhow!("action not found for test {}", test_subject))); } }; let result = match self @@ -580,7 +577,7 @@ impl Iterator for TestManifest { .object_for_subject_predicate(&test_subject, &*mf::RESULT) { Some(Term::NamedNode(n)) => Some(n.as_str().to_owned()), - Some(_) => return Some(Err(format_err!("invalid result"))), + Some(_) => return Some(Err(anyhow!("invalid result"))), None => None, }; Some(Ok(Test { @@ -595,7 +592,7 @@ impl Iterator for TestManifest { result, })) } - Some(_) => Some(Err(format_err!("invalid test list"))), + Some(_) => Some(Err(anyhow!("invalid test list"))), None => { match self.manifests_to_do.pop() { Some(url) => { @@ -620,7 +617,7 @@ impl Iterator for TestManifest { }), ); } - Some(_) => return Some(Err(format_err!("invalid tests list"))), + Some(_) => return Some(Err(anyhow!("invalid tests list"))), None => (), } @@ -636,10 +633,7 @@ impl Iterator for TestManifest { )); } Some(term) => { - return Some(Err(format_err!( - "Invalid tests list. Got term {}", - term - ))); + return Some(Err(anyhow!("Invalid tests list. Got term {}", term))); } None => (), } @@ -723,7 +717,7 @@ impl ServiceHandler for StaticServiceHandler { if let QueryResult::Bindings(iterator) = self .services .get(service_name) - .ok_or_else(|| format_err!("Service {} not found", service_name))? + .ok_or_else(|| anyhow!("Service {} not found", service_name))? .connection()? .prepare_query_from_pattern( &graph_pattern, @@ -739,7 +733,7 @@ impl ServiceHandler for StaticServiceHandler { Box::new(collected.into_iter()), )) } else { - Err(format_err!("Expected bindings but got another QueryResult")) + Err(anyhow!("Expected bindings but got another QueryResult")) } } }