Breaking: Uses anyhow instead of failure

Closes #25
pull/26/head
Tpt 5 years ago
parent caab54960a
commit 73f61884c1
  1. 2
      lib/Cargo.toml
  2. 28
      lib/benches/sparql_query.rs
  3. 2
      lib/src/lib.rs
  4. 6
      lib/src/sparql/eval.rs
  5. 4
      lib/src/sparql/json_results.rs
  6. 4
      lib/src/sparql/mod.rs
  7. 6
      lib/src/sparql/model.rs
  8. 9
      lib/src/sparql/plan_builder.rs
  9. 52
      lib/src/sparql/xml_results.rs
  10. 20
      lib/src/store/memory.rs
  11. 20
      lib/src/store/numeric_encoder.rs
  12. 4
      lib/src/store/rocksdb.rs
  13. 14
      lib/tests/service_test_cases.rs
  14. 44
      lib/tests/sparql_test_cases.rs

@ -20,7 +20,7 @@ md-5 = "0.8"
sha-1 = "0.8" sha-1 = "0.8"
sha2 = "0.8" sha2 = "0.8"
digest = "0.8" digest = "0.8"
failure = "0.1" anyhow = "1"
regex = "1" regex = "1"
rio_api = "0.4" rio_api = "0.4"
rio_turtle = "0.4" rio_turtle = "0.4"

@ -1,5 +1,5 @@
use anyhow::anyhow;
use criterion::{criterion_group, criterion_main, Criterion}; use criterion::{criterion_group, criterion_main, Criterion};
use failure::format_err;
use oxigraph::model::vocab::rdf; use oxigraph::model::vocab::rdf;
use oxigraph::model::*; use oxigraph::model::*;
use oxigraph::sparql::*; use oxigraph::sparql::*;
@ -55,7 +55,7 @@ fn to_relative_path(url: &str) -> Result<String> {
"rdf-tests/sparql11/", "rdf-tests/sparql11/",
)) ))
} else { } 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<impl BufRead> {
base_path.push(to_relative_path(url)?); base_path.push(to_relative_path(url)?);
Ok(BufReader::new(File::open(&base_path).map_err(|e| { 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") { } else if url.ends_with(".rdf") {
GraphSyntax::RdfXml GraphSyntax::RdfXml
} else { } 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)) 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(); let n = n.clone().into();
match self.graph.object_for_subject_predicate(&n, &qt::QUERY) { match self.graph.object_for_subject_predicate(&n, &qt::QUERY) {
Some(Term::NamedNode(q)) => q.as_str().to_owned(), Some(Term::NamedNode(q)) => q.as_str().to_owned(),
Some(_) => return Some(Err(format_err!("invalid query"))), Some(_) => return Some(Err(anyhow!("invalid query"))),
None => return Some(Err(format_err!("query not found"))), None => return Some(Err(anyhow!("query not found"))),
} }
} }
Some(_) => return Some(Err(format_err!("invalid action"))), Some(_) => return Some(Err(anyhow!("invalid action"))),
None => { None => {
return Some(Err(format_err!( return Some(Err(anyhow!("action not found for test {}", test_subject)));
"action not found for test {}",
test_subject
)));
} }
}; };
Some(Ok(Test { kind, query })) Some(Ok(Test { kind, query }))
} }
Some(_) => Some(Err(format_err!("invalid test list"))), Some(_) => Some(Err(anyhow!("invalid test list"))),
None => { None => {
match self.manifests_to_do.pop() { match self.manifests_to_do.pop() {
Some(url) => { 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 => (), None => (),
} }
@ -269,10 +266,7 @@ impl Iterator for TestManifest {
)); ));
} }
Some(term) => { Some(term) => {
return Some(Err(format_err!( return Some(Err(anyhow!("Invalid tests list. Got term {}", term)));
"Invalid tests list. Got term {}",
term
)));
} }
None => (), None => (),
} }

@ -109,7 +109,7 @@ pub mod sparql;
pub(crate) mod store; pub(crate) mod store;
mod syntax; mod syntax;
pub use failure::Error; pub use anyhow::Error;
pub type Result<T> = ::std::result::Result<T, Error>; pub type Result<T> = ::std::result::Result<T, Error>;
pub use crate::repository::Repository; pub use crate::repository::Repository;
pub use crate::repository::RepositoryConnection; pub use crate::repository::RepositoryConnection;

@ -8,8 +8,8 @@ use crate::sparql::ServiceHandler;
use crate::store::numeric_encoder::*; use crate::store::numeric_encoder::*;
use crate::store::StoreConnection; use crate::store::StoreConnection;
use crate::Result; use crate::Result;
use anyhow::anyhow;
use digest::Digest; use digest::Digest;
use failure::format_err;
use md5::Md5; use md5::Md5;
use rand::random; use rand::random;
use regex::{Regex, RegexBuilder}; use regex::{Regex, RegexBuilder};
@ -220,7 +220,7 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator<S> {
if let Some(graph_name) = get_pattern_value(graph_name, &tuple) { if let Some(graph_name) = get_pattern_value(graph_name, &tuple) {
graph_name graph_name
} else { } 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" "Unknown graph name is not allowed when evaluating property path"
)))); ))));
return result; return result;
@ -493,7 +493,7 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator<S> {
) -> Result<EncodedTuplesIterator<'b>> { ) -> Result<EncodedTuplesIterator<'b>> {
let service_name = self.dataset.decode_named_node( let service_name = self.dataset.decode_named_node(
get_pattern_value(service_name, from) 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( Ok(self.encode_bindings(
variables, variables,

@ -3,7 +3,7 @@
use crate::model::*; use crate::model::*;
use crate::sparql::model::*; use crate::sparql::model::*;
use crate::Result; use crate::Result;
use failure::format_err; use anyhow::anyhow;
use std::io::Write; use std::io::Write;
pub fn write_json_results<W: Write>(results: QueryResult<'_>, mut sink: W) -> Result<W> { pub fn write_json_results<W: Write>(results: QueryResult<'_>, mut sink: W) -> Result<W> {
@ -79,7 +79,7 @@ pub fn write_json_results<W: Write>(results: QueryResult<'_>, mut sink: W) -> Re
sink.write_all(b"]}}")?; sink.write_all(b"]}}")?;
} }
QueryResult::Graph(_) => { QueryResult::Graph(_) => {
return Err(format_err!( return Err(anyhow!(
"Graphs could not be formatted to SPARQL query results XML format" "Graphs could not be formatted to SPARQL query results XML format"
)); ));
} }

@ -18,7 +18,7 @@ use crate::sparql::plan::{DatasetView, PlanNode};
use crate::sparql::plan_builder::PlanBuilder; use crate::sparql::plan_builder::PlanBuilder;
use crate::store::StoreConnection; use crate::store::StoreConnection;
use crate::Result; use crate::Result;
use failure::format_err; use anyhow::anyhow;
use rio_api::iri::Iri; use rio_api::iri::Iri;
use std::fmt; use std::fmt;
@ -180,7 +180,7 @@ struct EmptyServiceHandler;
impl ServiceHandler for EmptyServiceHandler { impl ServiceHandler for EmptyServiceHandler {
fn handle<'a>(&'a self, _: &NamedNode, _: &'a GraphPattern) -> Result<BindingsIterator<'a>> { fn handle<'a>(&'a self, _: &NamedNode, _: &'a GraphPattern) -> Result<BindingsIterator<'a>> {
Err(format_err!("The SERVICE feature is not implemented")) Err(anyhow!("The SERVICE feature is not implemented"))
} }
} }

@ -2,7 +2,7 @@ use crate::model::*;
use crate::sparql::json_results::write_json_results; use crate::sparql::json_results::write_json_results;
use crate::sparql::xml_results::{read_xml_results, write_xml_results}; use crate::sparql::xml_results::{read_xml_results, write_xml_results};
use crate::{FileSyntax, GraphSyntax, Result}; use crate::{FileSyntax, GraphSyntax, Result};
use failure::format_err; use anyhow::anyhow;
use rand::random; use rand::random;
use rio_api::formatter::TriplesFormatter; use rio_api::formatter::TriplesFormatter;
use rio_turtle::{NTriplesFormatter, TurtleFormatter}; use rio_turtle::{NTriplesFormatter, TurtleFormatter};
@ -61,7 +61,7 @@ impl<'a> QueryResult<'a> {
} }
}) })
} else { } else {
Err(format_err!( Err(anyhow!(
"Bindings or booleans could not be formatted as an RDF graph" "Bindings or booleans could not be formatted as an RDF graph"
)) ))
} }
@ -168,7 +168,7 @@ impl Variable {
pub fn name(&self) -> Result<&str> { pub fn name(&self) -> Result<&str> {
match self { match self {
Variable::Variable { name } => Ok(name), Variable::Variable { name } => Ok(name),
_ => Err(format_err!("The variable {} has no name", self)), _ => Err(anyhow!("The variable {} has no name", self)),
} }
} }
} }

@ -6,7 +6,7 @@ use crate::sparql::plan::PlanPropertyPath;
use crate::sparql::plan::*; use crate::sparql::plan::*;
use crate::store::numeric_encoder::{Encoder, ENCODED_DEFAULT_GRAPH}; use crate::store::numeric_encoder::{Encoder, ENCODED_DEFAULT_GRAPH};
use crate::Result; use crate::Result;
use failure::format_err; use anyhow::anyhow;
use std::collections::HashSet; use std::collections::HashSet;
pub struct PlanBuilder<E: Encoder> { pub struct PlanBuilder<E: Encoder> {
@ -654,7 +654,7 @@ impl<E: Encoder> PlanBuilder<E> {
"string", "string",
)? )?
} else { } else {
return Err(format_err!("Not supported custom function {}", expression)); return Err(anyhow!("Not supported custom function {}", expression));
} }
} }
}, },
@ -680,10 +680,7 @@ impl<E: Encoder> PlanBuilder<E> {
graph_name, graph_name,
)?))) )?)))
} else { } else {
Err(format_err!( Err(anyhow!("The xsd:{} casting takes only one parameter", name))
"The xsd:{} casting takes only one parameter",
name
))
} }
} }

@ -3,7 +3,7 @@
use crate::model::*; use crate::model::*;
use crate::sparql::model::*; use crate::sparql::model::*;
use crate::Result; use crate::Result;
use failure::format_err; use anyhow::anyhow;
use quick_xml::events::BytesDecl; use quick_xml::events::BytesDecl;
use quick_xml::events::BytesEnd; use quick_xml::events::BytesEnd;
use quick_xml::events::BytesStart; use quick_xml::events::BytesStart;
@ -99,7 +99,7 @@ pub fn write_xml_results<W: Write>(results: QueryResult<'_>, sink: W) -> Result<
writer.write_event(Event::End(BytesEnd::borrowed(b"sparql")))?; writer.write_event(Event::End(BytesEnd::borrowed(b"sparql")))?;
} }
QueryResult::Graph(_) => { QueryResult::Graph(_) => {
return Err(format_err!( return Err(anyhow!(
"Graphs could not be formatted to SPARQL query results XML format" "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<QueryResult<'a>
let (ns, event) = reader.read_namespaced_event(&mut buffer, &mut namespace_buffer)?; let (ns, event) = reader.read_namespaced_event(&mut buffer, &mut namespace_buffer)?;
if let Some(ns) = ns { if let Some(ns) = ns {
if ns != b"http://www.w3.org/2005/sparql-results#".as_ref() { 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: {}", "Unexpected namespace found in RDF/XML query result: {}",
reader.decode(ns)? reader.decode(ns)?
)); ));
@ -144,14 +144,14 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result<QueryResult<'a>
if event.name() == b"sparql" { if event.name() == b"sparql" {
state = State::Sparql; state = State::Sparql;
} else { } else {
return Err(format_err!("Expecting <sparql> tag, found {}", reader.decode(event.name())?)); return Err(anyhow!("Expecting <sparql> tag, found {}", reader.decode(event.name())?));
} }
} }
State::Sparql => { State::Sparql => {
if event.name() == b"head" { if event.name() == b"head" {
state = State::Head; state = State::Head;
} else { } else {
return Err(format_err!("Expecting <head> tag, found {}", reader.decode(event.name())?)); return Err(anyhow!("Expecting <head> tag, found {}", reader.decode(event.name())?));
} }
} }
State::Head => { State::Head => {
@ -159,12 +159,12 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result<QueryResult<'a>
let name = event.attributes() let name = event.attributes()
.filter_map(|attr| attr.ok()) .filter_map(|attr| attr.ok())
.find(|attr| attr.key == b"name") .find(|attr| attr.key == b"name")
.ok_or_else(|| format_err!("No name attribute found for the <variable> tag"))?; .ok_or_else(|| anyhow!("No name attribute found for the <variable> tag"))?;
variables.push(name.unescape_and_decode_value(&reader)?); variables.push(name.unescape_and_decode_value(&reader)?);
} else if event.name() == b"link" { } else if event.name() == b"link" {
// no op // no op
} else { } else {
return Err(format_err!("Expecting <variable> or <link> tag, found {}", reader.decode(event.name())?)); return Err(anyhow!("Expecting <variable> or <link> tag, found {}", reader.decode(event.name())?));
} }
} }
State::AfterHead => { State::AfterHead => {
@ -186,17 +186,17 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result<QueryResult<'a>
}), }),
))); )));
} else if event.name() != b"link" && event.name() != b"results" && event.name() != b"boolean" { } 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 <boolean> tag: {}", reader.decode(event.name())?)) State::Boolean => return Err(anyhow!("Unexpected tag inside of <boolean> tag: {}", reader.decode(event.name())?))
}, },
Event::Empty(event) => match state { Event::Empty(event) => match state {
State::Sparql => { State::Sparql => {
if event.name() == b"head" { if event.name() == b"head" {
state = State::AfterHead; state = State::AfterHead;
} else { } else {
return Err(format_err!("Expecting <head> tag, found {}", reader.decode(event.name())?)); return Err(anyhow!("Expecting <head> tag, found {}", reader.decode(event.name())?));
} }
} }
State::Head => { State::Head => {
@ -204,12 +204,12 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result<QueryResult<'a>
let name = event.attributes() let name = event.attributes()
.filter_map(|v| v.ok()) .filter_map(|v| v.ok())
.find(|attr| attr.key == b"name") .find(|attr| attr.key == b"name")
.ok_or_else(|| format_err!("No name attribute found for the <variable> tag"))?; .ok_or_else(|| anyhow!("No name attribute found for the <variable> tag"))?;
variables.push(name.unescape_and_decode_value(&reader)?); variables.push(name.unescape_and_decode_value(&reader)?);
} else if event.name() == b"link" { } else if event.name() == b"link" {
// no op // no op
} else { } else {
return Err(format_err!("Expecting <variable> or <link> tag, found {}", reader.decode(event.name())?)); return Err(anyhow!("Expecting <variable> or <link> tag, found {}", reader.decode(event.name())?));
} }
}, },
State::AfterHead => { State::AfterHead => {
@ -219,10 +219,10 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result<QueryResult<'a>
Box::new(empty()), Box::new(empty()),
))) )))
} else { } 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) => { Event::Text(event) => {
let value = event.unescaped()?; let value = event.unescaped()?;
@ -233,18 +233,18 @@ pub fn read_xml_results<'a>(source: impl BufRead + 'a) -> Result<QueryResult<'a>
} else if value.as_ref() == b"false" { } else if value.as_ref() == b"false" {
Ok(QueryResult::Boolean(false)) Ok(QueryResult::Boolean(false))
} else { } 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 { Event::End(_) => if let State::Head = state {
state = State::AfterHead; state = State::AfterHead;
} else { } else {
return Err(format_err!("Unexpected early file end. All results file should have a <head> and a <result> or <boolean> tag")); return Err(anyhow!("Unexpected early file end. All results file should have a <head> and a <result> or <boolean> tag"));
}, },
Event::Eof => return Err(format_err!("Unexpected early file end. All results file should have a <head> and a <result> or <boolean> tag")), Event::Eof => return Err(anyhow!("Unexpected early file end. All results file should have a <head> and a <result> or <boolean> tag")),
_ => (), _ => (),
} }
} }
@ -292,7 +292,7 @@ impl<R: BufRead> ResultsIterator<R> {
.read_namespaced_event(&mut self.buffer, &mut self.namespace_buffer)?; .read_namespaced_event(&mut self.buffer, &mut self.namespace_buffer)?;
if let Some(ns) = ns { if let Some(ns) = ns {
if ns != b"http://www.w3.org/2005/sparql-results#".as_ref() { 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: {}", "Unexpected namespace found in RDF/XML query result: {}",
self.reader.decode(ns)? self.reader.decode(ns)?
)); ));
@ -304,7 +304,7 @@ impl<R: BufRead> ResultsIterator<R> {
if event.name() == b"result" { if event.name() == b"result" {
state = State::Result; state = State::Result;
} else { } else {
return Err(format_err!( return Err(anyhow!(
"Expecting <result>, found {}", "Expecting <result>, found {}",
self.reader.decode(event.name())? self.reader.decode(event.name())?
)); ));
@ -319,14 +319,14 @@ impl<R: BufRead> ResultsIterator<R> {
{ {
Some(attr) => current_var = Some(attr.unescaped_value()?.to_vec()), Some(attr) => current_var = Some(attr.unescaped_value()?.to_vec()),
None => { None => {
return Err(format_err!( return Err(anyhow!(
"No name attribute found for the <binding> tag" "No name attribute found for the <binding> tag"
)); ));
} }
} }
state = State::Binding; state = State::Binding;
} else { } else {
return Err(format_err!( return Err(anyhow!(
"Expecting <binding>, found {}", "Expecting <binding>, found {}",
self.reader.decode(event.name())? self.reader.decode(event.name())?
)); ));
@ -334,7 +334,7 @@ impl<R: BufRead> ResultsIterator<R> {
} }
State::Binding => { State::Binding => {
if term.is_some() { if term.is_some() {
return Err(format_err!( return Err(anyhow!(
"There is already a value for the current binding" "There is already a value for the current binding"
)); ));
} }
@ -356,7 +356,7 @@ impl<R: BufRead> ResultsIterator<R> {
} }
state = State::Literal; state = State::Literal;
} else { } else {
return Err(format_err!( return Err(anyhow!(
"Expecting <uri>, <bnode> or <literal> found {}", "Expecting <uri>, <bnode> or <literal> found {}",
self.reader.decode(event.name())? self.reader.decode(event.name())?
)); ));
@ -390,7 +390,7 @@ impl<R: BufRead> ResultsIterator<R> {
); );
} }
_ => { _ => {
return Err(format_err!( return Err(anyhow!(
"Unexpected textual value found: {}", "Unexpected textual value found: {}",
self.reader.decode(&data)? self.reader.decode(&data)?
)); ));
@ -404,7 +404,7 @@ impl<R: BufRead> ResultsIterator<R> {
if let Some(var) = &current_var { if let Some(var) = &current_var {
new_bindings[self.mapping[var]] = term.clone() new_bindings[self.mapping[var]] = term.clone()
} else { } else {
return Err(format_err!("No name found for <binding> tag")); return Err(anyhow!("No name found for <binding> tag"));
} }
term = None; term = None;
state = State::Result; state = State::Result;

@ -1,8 +1,9 @@
use crate::store::numeric_encoder::*; use crate::store::numeric_encoder::*;
use crate::store::*; use crate::store::*;
use crate::{Repository, Result}; use crate::{Repository, Result};
use failure::{Backtrace, Fail};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::error::Error;
use std::fmt;
use std::hash::Hash; use std::hash::Hash;
use std::iter::{empty, once}; use std::iter::{empty, once};
use std::sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard};
@ -681,16 +682,19 @@ impl StoreTransaction for MemoryTransaction<'_> {
} }
} }
#[derive(Debug, Fail)] #[derive(Debug)]
#[fail(display = "Mutex Mutex was poisoned")] struct MutexPoisonError {}
pub struct MutexPoisonError {
backtrace: Backtrace, impl fmt::Display for MutexPoisonError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Mutex was poisoned")
}
} }
impl Error for MutexPoisonError {}
impl<T> From<PoisonError<T>> for MutexPoisonError { impl<T> From<PoisonError<T>> for MutexPoisonError {
fn from(_: PoisonError<T>) -> Self { fn from(_: PoisonError<T>) -> Self {
Self { Self {}
backtrace: Backtrace::new(),
}
} }
} }

@ -3,7 +3,7 @@ use crate::model::vocab::xsd;
use crate::model::xsd::*; use crate::model::xsd::*;
use crate::model::*; use crate::model::*;
use crate::Result; use crate::Result;
use failure::format_err; use anyhow::anyhow;
use md5::digest::Digest; use md5::digest::Digest;
use md5::Md5; use md5::Md5;
use rand::random; use rand::random;
@ -604,7 +604,7 @@ impl<R: Read> TermReader for R {
buffer, 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)? { match self.decode_term(encoded)? {
Term::NamedNode(named_node) => Ok(named_node.into()), Term::NamedNode(named_node) => Ok(named_node.into()),
Term::BlankNode(blank_node) => Ok(blank_node.into()), Term::BlankNode(blank_node) => Ok(blank_node.into()),
Term::Literal(_) => Err(format_err!( Term::Literal(_) => Err(anyhow!("A literal has ben found instead of a named node")),
"A literal has ben found instead of a named node"
)),
} }
} }
fn decode_named_node(&self, encoded: EncodedTerm) -> Result<NamedNode> { fn decode_named_node(&self, encoded: EncodedTerm) -> Result<NamedNode> {
match self.decode_term(encoded)? { match self.decode_term(encoded)? {
Term::NamedNode(named_node) => Ok(named_node), 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" "A blank node has been found instead of a named node"
)), )),
Term::Literal(_) => Err(format_err!( Term::Literal(_) => Err(anyhow!("A literal has ben found instead of a named node")),
"A literal has ben found instead of a named node"
)),
} }
} }
@ -1148,9 +1144,7 @@ pub trait Decoder {
impl<S: StrLookup> Decoder for S { impl<S: StrLookup> Decoder for S {
fn decode_term(&self, encoded: EncodedTerm) -> Result<Term> { fn decode_term(&self, encoded: EncodedTerm) -> Result<Term> {
match encoded { match encoded {
EncodedTerm::DefaultGraph => { EncodedTerm::DefaultGraph => Err(anyhow!("The default graph tag is not a valid term")),
Err(format_err!("The default graph tag is not a valid term"))
}
EncodedTerm::NamedNode { iri_id } => { EncodedTerm::NamedNode { iri_id } => {
Ok(NamedNode::new_unchecked(get_required_str(self, iri_id)?).into()) Ok(NamedNode::new_unchecked(get_required_str(self, iri_id)?).into())
} }
@ -1189,7 +1183,7 @@ impl<S: StrLookup> Decoder for S {
fn get_required_str(lookup: &impl StrLookup, id: u128) -> Result<String> { fn get_required_str(lookup: &impl StrLookup, id: u128) -> Result<String> {
lookup.get_str(id)?.ok_or_else(|| { lookup.get_str(id)?.ok_or_else(|| {
format_err!( anyhow!(
"Not able to find the string with id {} in the string store", "Not able to find the string with id {} in the string store",
id id
) )

@ -1,7 +1,7 @@
use crate::store::numeric_encoder::*; use crate::store::numeric_encoder::*;
use crate::store::{Store, StoreConnection, StoreRepositoryConnection, StoreTransaction}; use crate::store::{Store, StoreConnection, StoreRepositoryConnection, StoreTransaction};
use crate::{Repository, Result}; use crate::{Repository, Result};
use failure::format_err; use anyhow::anyhow;
use rocksdb::*; use rocksdb::*;
use std::io::Cursor; use std::io::Cursor;
use std::iter::{empty, once}; use std::iter::{empty, once};
@ -596,7 +596,7 @@ impl RocksDbStoreInnerTransaction<'_> {
fn get_cf<'a>(db: &'a DB, name: &str) -> Result<&'a ColumnFamily> { fn get_cf<'a>(db: &'a DB, name: &str) -> Result<&'a ColumnFamily> {
db.cf_handle(name) 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<Item = Result<E>> + 'a>( fn wrap_error<'a, E: 'a, I: Iterator<Item = Result<E>> + 'a>(

@ -1,4 +1,4 @@
use failure::format_err; use anyhow::anyhow;
use oxigraph::model::*; use oxigraph::model::*;
use oxigraph::sparql::{ use oxigraph::sparql::{
BindingsIterator, GraphPattern, PreparedQuery, QueryOptions, QueryResult, ServiceHandler, BindingsIterator, GraphPattern, PreparedQuery, QueryOptions, QueryResult, ServiceHandler,
@ -73,7 +73,7 @@ fn two_service_test() {
.as_ref(); .as_ref();
do_pattern(triples, graph_pattern, QueryOptions::default()) do_pattern(triples, graph_pattern, QueryOptions::default())
} else { } else {
Err(format_err!("not found")) Err(anyhow!("not found"))
} }
} }
} }
@ -124,7 +124,7 @@ fn silent_service_empty_set_test() {
_: &NamedNode, _: &NamedNode,
_: &'a GraphPattern, _: &'a GraphPattern,
) -> Result<BindingsIterator<'a>> { ) -> Result<BindingsIterator<'a>> {
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, _: &NamedNode,
_: &'a GraphPattern, _: &'a GraphPattern,
) -> Result<BindingsIterator<'a>> { ) -> Result<BindingsIterator<'a>> {
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()), Box::new(collected.into_iter()),
)) ))
} }
_ => Err(format_err!( _ => Err(anyhow!("Excpected bindings but got another QueryResult")),
"Excpected bindings but got another QueryResult"
)),
} }
} }
@ -256,7 +254,7 @@ fn pattern_repository<'a>(
Box::new(collected.into_iter()), Box::new(collected.into_iter()),
)) ))
} }
_ => Err(format_err!("Expected bindings but got another QueryResult")), _ => Err(anyhow!("Expected bindings but got another QueryResult")),
} }
} }

@ -1,5 +1,5 @@
///! Integration tests based on [SPARQL 1.1 Test Cases](https://www.w3.org/2009/sparql/docs/tests/README.html) ///! 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::rdf;
use oxigraph::model::vocab::rdfs; use oxigraph::model::vocab::rdfs;
use oxigraph::model::*; use oxigraph::model::*;
@ -162,27 +162,27 @@ fn sparql_w3c_query_evaluation_testsuite() -> Result<()> {
.connection()? .connection()?
.prepare_query(&read_file_to_string(&test.query)?, QueryOptions::default().with_base_iri(&test.query).with_service_handler(StaticServiceHandler::new(&test.service_data)?)) .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: {}", "Failure to parse query of {} with error: {}",
test, error test, error
)), )),
Ok(query) => match query.exec() { Ok(query) => match query.exec() {
Err(error) => Err(format_err!( Err(error) => Err(anyhow!(
"Failure to execute query of {} with error: {}", "Failure to execute query of {} with error: {}",
test, error test, error
)), )),
Ok(result) => { Ok(result) => {
let expected_graph = 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 let with_order = expected_graph
.triples_for_predicate(&rs::INDEX) .triples_for_predicate(&rs::INDEX)
.next() .next()
.is_some(); .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) { if actual_graph.is_isomorphic(&expected_graph) {
Ok(()) Ok(())
} else { } 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, test,
expected_graph, expected_graph,
actual_graph, actual_graph,
@ -240,7 +240,7 @@ fn load_graph_to_repository(
} else if url.ends_with(".rdf") { } else if url.ends_with(".rdf") {
GraphSyntax::RdfXml GraphSyntax::RdfXml
} else { } 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)) connection.load_graph(read_file(url)?, syntax, to_graph_name, Some(url))
} }
@ -276,7 +276,7 @@ fn to_relative_path(url: &str) -> Result<String> {
"rdf-tests/sparql11/", "rdf-tests/sparql11/",
)) ))
} else { } 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<impl BufRead> {
base_path.push(to_relative_path(url)?); base_path.push(to_relative_path(url)?);
Ok(BufReader::new(File::open(&base_path).map_err(|e| { 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 n = n.clone().into();
let query = match self.graph.object_for_subject_predicate(&n, &qt::QUERY) { let query = match self.graph.object_for_subject_predicate(&n, &qt::QUERY) {
Some(Term::NamedNode(q)) => q.as_str().to_owned(), Some(Term::NamedNode(q)) => q.as_str().to_owned(),
Some(_) => return Some(Err(format_err!("invalid query"))), Some(_) => return Some(Err(anyhow!("invalid query"))),
None => return Some(Err(format_err!("query not found"))), None => return Some(Err(anyhow!("query not found"))),
}; };
let data = match self.graph.object_for_subject_predicate(&n, &qt::DATA) { let data = match self.graph.object_for_subject_predicate(&n, &qt::DATA) {
Some(Term::NamedNode(q)) => Some(q.as_str().to_owned()), Some(Term::NamedNode(q)) => Some(q.as_str().to_owned()),
@ -567,12 +567,9 @@ impl Iterator for TestManifest {
.collect(); .collect();
(query, data, graph_data, service_data) (query, data, graph_data, service_data)
} }
Some(_) => return Some(Err(format_err!("invalid action"))), Some(_) => return Some(Err(anyhow!("invalid action"))),
None => { None => {
return Some(Err(format_err!( return Some(Err(anyhow!("action not found for test {}", test_subject)));
"action not found for test {}",
test_subject
)));
} }
}; };
let result = match self let result = match self
@ -580,7 +577,7 @@ impl Iterator for TestManifest {
.object_for_subject_predicate(&test_subject, &*mf::RESULT) .object_for_subject_predicate(&test_subject, &*mf::RESULT)
{ {
Some(Term::NamedNode(n)) => Some(n.as_str().to_owned()), 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, None => None,
}; };
Some(Ok(Test { Some(Ok(Test {
@ -595,7 +592,7 @@ impl Iterator for TestManifest {
result, result,
})) }))
} }
Some(_) => Some(Err(format_err!("invalid test list"))), Some(_) => Some(Err(anyhow!("invalid test list"))),
None => { None => {
match self.manifests_to_do.pop() { match self.manifests_to_do.pop() {
Some(url) => { 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 => (), None => (),
} }
@ -636,10 +633,7 @@ impl Iterator for TestManifest {
)); ));
} }
Some(term) => { Some(term) => {
return Some(Err(format_err!( return Some(Err(anyhow!("Invalid tests list. Got term {}", term)));
"Invalid tests list. Got term {}",
term
)));
} }
None => (), None => (),
} }
@ -723,7 +717,7 @@ impl ServiceHandler for StaticServiceHandler {
if let QueryResult::Bindings(iterator) = self if let QueryResult::Bindings(iterator) = self
.services .services
.get(service_name) .get(service_name)
.ok_or_else(|| format_err!("Service {} not found", service_name))? .ok_or_else(|| anyhow!("Service {} not found", service_name))?
.connection()? .connection()?
.prepare_query_from_pattern( .prepare_query_from_pattern(
&graph_pattern, &graph_pattern,
@ -739,7 +733,7 @@ impl ServiceHandler for StaticServiceHandler {
Box::new(collected.into_iter()), Box::new(collected.into_iter()),
)) ))
} else { } else {
Err(format_err!("Expected bindings but got another QueryResult")) Err(anyhow!("Expected bindings but got another QueryResult"))
} }
} }
} }

Loading…
Cancel
Save