From f5aa6b2c2c8bb4455a4f0a839d979149cee54f81 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Thu, 16 Mar 2017 19:16:56 +0000 Subject: [PATCH] Pre: add mentat_query_algebrizer::errors. --- query-algebrizer/Cargo.toml | 2 ++ query-algebrizer/src/cc.rs | 12 +++++++--- query-algebrizer/src/errors.rs | 40 ++++++++++++++++++++++++++++++++++ query-algebrizer/src/lib.rs | 4 ++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 query-algebrizer/src/errors.rs diff --git a/query-algebrizer/Cargo.toml b/query-algebrizer/Cargo.toml index 850799d8..4a1dfeb0 100644 --- a/query-algebrizer/Cargo.toml +++ b/query-algebrizer/Cargo.toml @@ -4,6 +4,8 @@ version = "0.0.1" workspace = ".." [dependencies] +error-chain = "0.9.0" + [dependencies.mentat_core] path = "../core" diff --git a/query-algebrizer/src/cc.rs b/query-algebrizer/src/cc.rs index a881dd7f..7df66e9a 100644 --- a/query-algebrizer/src/cc.rs +++ b/query-algebrizer/src/cc.rs @@ -14,8 +14,8 @@ extern crate mentat_query; use std::fmt::{ Debug, Formatter, - Result, }; + use std::collections::{ BTreeMap, BTreeSet, @@ -39,6 +39,12 @@ use self::mentat_query::{ Variable, }; +use errors::{ + Error, + ErrorKind, + Result, +}; + use types::{ DatomsColumn, DatomsTable, @@ -192,7 +198,7 @@ pub enum EmptyBecause { } impl Debug for EmptyBecause { - fn fmt(&self, f: &mut Formatter) -> Result { + fn fmt(&self, f: &mut Formatter) -> ::std::fmt::Result { use self::EmptyBecause::*; match self { &TypeMismatch(ref var, ref existing, ref desired) => { @@ -223,7 +229,7 @@ impl Debug for EmptyBecause { } impl Debug for ConjoiningClauses { - fn fmt(&self, fmt: &mut Formatter) -> Result { + fn fmt(&self, fmt: &mut Formatter) -> ::std::fmt::Result { fmt.debug_struct("ConjoiningClauses") .field("is_known_empty", &self.is_known_empty) .field("from", &self.from) diff --git a/query-algebrizer/src/errors.rs b/query-algebrizer/src/errors.rs new file mode 100644 index 00000000..1db9b371 --- /dev/null +++ b/query-algebrizer/src/errors.rs @@ -0,0 +1,40 @@ +// Copyright 2016 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 mentat_query; + +use self::mentat_query::{ + PlainSymbol, + Variable, +}; + +error_chain! { + types { + Error, ErrorKind, ResultExt, Result; + } + + errors { + UnknownFunction(name: PlainSymbol) { + description("no such function") + display("no function named {}", name) + } + + InvalidNumberOfArguments(name: PlainSymbol, number: usize, expected: usize) { + description("invalid number of arguments") + display("invalid number of arguments to {}: expected {}, got {}.", name, expected, number) + } + + UnboundVariable(var: Variable) { + description("unbound variable in function call") + display("unbound variable: {}", var.0) + } + } +} + diff --git a/query-algebrizer/src/lib.rs b/query-algebrizer/src/lib.rs index 653ea96a..1a67908b 100644 --- a/query-algebrizer/src/lib.rs +++ b/query-algebrizer/src/lib.rs @@ -8,9 +8,13 @@ // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. +#[macro_use] +extern crate error_chain; + extern crate mentat_core; extern crate mentat_query; +mod errors; mod types; mod cc;