remove failure dependency
This commit is contained in:
parent
b4f41cf5e9
commit
c10c3a589e
@ -16,6 +16,10 @@ All notes should be prepended with the location of the change, e.g. `(proto)` or
|
||||
|
||||
- (resolver) testing module for generic tests across generic async runtime impls (@chunyingw) #979
|
||||
|
||||
### Removed
|
||||
|
||||
- (all) failure is no longer used for error types, std::Error impls only
|
||||
|
||||
## 0.18.1
|
||||
|
||||
### Fixes
|
||||
|
69
Cargo.lock
generated
69
Cargo.lock
generated
@ -193,26 +193,6 @@ dependencies = [
|
||||
"termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "failure"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "failure_derive"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fallible-iterator"
|
||||
version = "0.2.0"
|
||||
@ -941,17 +921,6 @@ dependencies = [
|
||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synstructure"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.1.0"
|
||||
@ -981,6 +950,24 @@ dependencies = [
|
||||
"unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"thiserror-impl 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.0.1"
|
||||
@ -1093,9 +1080,9 @@ dependencies = [
|
||||
name = "trust-dns-client"
|
||||
version = "0.18.1"
|
||||
dependencies = [
|
||||
"backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1105,6 +1092,7 @@ dependencies = [
|
||||
"ring 0.16.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustls 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"trust-dns-https 0.18.1",
|
||||
"trust-dns-proto 0.18.1",
|
||||
@ -1128,15 +1116,16 @@ dependencies = [
|
||||
name = "trust-dns-https"
|
||||
version = "0.18.1"
|
||||
dependencies = [
|
||||
"backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"h2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustls 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-rustls 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"trust-dns-proto 0.18.1",
|
||||
@ -1197,10 +1186,10 @@ name = "trust-dns-proto"
|
||||
version = "0.18.1"
|
||||
dependencies = [
|
||||
"async-trait 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"enum-as-inner 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1211,6 +1200,7 @@ dependencies = [
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -1219,9 +1209,9 @@ dependencies = [
|
||||
name = "trust-dns-resolver"
|
||||
version = "0.18.1"
|
||||
dependencies = [
|
||||
"backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipconfig 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1231,6 +1221,7 @@ dependencies = [
|
||||
"rustls 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-openssl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-rustls 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1261,11 +1252,11 @@ dependencies = [
|
||||
name = "trust-dns-server"
|
||||
version = "0.18.1"
|
||||
dependencies = [
|
||||
"backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"enum-as-inner 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"h2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1274,6 +1265,7 @@ dependencies = [
|
||||
"rusqlite 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustls 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-openssl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1583,8 +1575,6 @@ dependencies = [
|
||||
"checksum endian-type 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
|
||||
"checksum enum-as-inner 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "900a6c7fbe523f4c2884eaf26b57b81bb69b6810a01a236390a7ac021d09492e"
|
||||
"checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
||||
"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9"
|
||||
"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08"
|
||||
"checksum fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
|
||||
"checksum fallible-streaming-iterator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
|
||||
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||
@ -1673,10 +1663,11 @@ dependencies = [
|
||||
"checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
"checksum syn 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4ff033220a41d1a57d8125eab57bf5263783dfdcc18688b1dacc6ce9651ef8"
|
||||
"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
|
||||
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
|
||||
"checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e"
|
||||
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||
"checksum thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6f357d1814b33bc2dc221243f8424104bfe72dbe911d5b71b3816a2dff1c977e"
|
||||
"checksum thiserror-impl 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2e25d25307eb8436894f727aba8f65d07adf02e5b35a13cebed48bd282bfef"
|
||||
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
|
||||
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
|
||||
"checksum tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ffa2fdcfa937b20cb3c822a635ceecd5fc1a27a6a474527e5516aa24b8c8820a"
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2019 Benjamin Fry <benjaminfry@me.com>
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
|
@ -65,9 +65,9 @@ name = "trust_dns_client"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
backtrace = "0.3.40"
|
||||
chrono = "0.4"
|
||||
data-encoding = "2.1.0"
|
||||
failure = "0.1"
|
||||
futures = "0.3.0"
|
||||
lazy_static = "1.0"
|
||||
log = "0.4"
|
||||
@ -77,6 +77,7 @@ rand = "0.7"
|
||||
ring = { version = "0.16", optional = true, features = ["std"]}
|
||||
rustls = { version = "0.16", optional = true }
|
||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||
thiserror = "1.0.9"
|
||||
tokio = { version = "0.2.1", features = ["rt-core"] }
|
||||
trust-dns-https = { version = "0.18.1", path = "../https", optional = true }
|
||||
trust-dns-proto = { version = "0.18.1", path = "../proto", features = ["dnssec"]}
|
||||
|
@ -1,144 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Benjamin Fry <benjaminfry@me.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
//! Error types for the crate
|
||||
|
||||
use std::{fmt, io};
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use futures::channel::mpsc::SendError;
|
||||
use futures::channel::mpsc;
|
||||
use thiserror::Error;
|
||||
use trust_dns_proto::error::{ProtoError, ProtoErrorKind};
|
||||
|
||||
use crate::error::{DnsSecError, DnsSecErrorKind};
|
||||
use crate::proto::{trace, ExtBacktrace};
|
||||
|
||||
/// An alias for results returned by functions of this crate
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
/// The error kind for errors that get returned in the crate
|
||||
#[derive(Eq, PartialEq, Debug, Fail)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ErrorKind {
|
||||
/// An error with an arbitrary message, referenced as &'static str
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Message(&'static str),
|
||||
|
||||
/// An error with an arbitrary message, stored as String
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Msg(String),
|
||||
|
||||
// foreign
|
||||
/// A dnssec error
|
||||
#[fail(display = "dnssec error")]
|
||||
DnsSec,
|
||||
#[error("dnssec error")]
|
||||
DnsSec(#[from] DnsSecError),
|
||||
|
||||
/// An error got returned from IO
|
||||
#[fail(display = "io error")]
|
||||
Io,
|
||||
#[error("io error")]
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
/// An error got returned by the trust-dns-proto crate
|
||||
#[fail(display = "proto error")]
|
||||
Proto,
|
||||
#[error("proto error")]
|
||||
Proto(#[from] ProtoError),
|
||||
|
||||
/// Queue send error
|
||||
#[error("error sending to mpsc: {0}")]
|
||||
SendError(#[from] mpsc::SendError),
|
||||
|
||||
/// A request timed out
|
||||
#[fail(display = "request timed out")]
|
||||
#[error("request timed out")]
|
||||
Timeout,
|
||||
}
|
||||
|
||||
impl Clone for ErrorKind {
|
||||
fn clone(&self) -> Self {
|
||||
use self::ErrorKind::*;
|
||||
match *self {
|
||||
match self {
|
||||
Message(msg) => Message(msg),
|
||||
Msg(ref msg) => Msg(msg.clone()),
|
||||
// foreign
|
||||
DnsSec => DnsSec,
|
||||
Io => Io,
|
||||
Proto => Proto,
|
||||
DnsSec(dnssec) => DnsSec(dnssec.clone()),
|
||||
Io(io) => Io(std::io::Error::from(io.kind())),
|
||||
Proto(proto) => Proto(proto.clone()),
|
||||
SendError(e) => SendError(e.clone()),
|
||||
Timeout => Timeout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The error type for errors that get returned in the crate
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error, Clone)]
|
||||
pub struct Error {
|
||||
inner: Context<ErrorKind>,
|
||||
kind: ErrorKind,
|
||||
backtrack: Option<ExtBacktrace>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Get the kind of the error
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
self.inner.get_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Error {
|
||||
fn clone(&self) -> Self {
|
||||
use self::ErrorKind::*;
|
||||
match *self.kind() {
|
||||
Message(msg) => Message(msg).into(),
|
||||
Msg(ref msg) => Msg(msg.clone()).into(),
|
||||
//foreign
|
||||
DnsSec => DnsSec.into(),
|
||||
Io => Io.into(),
|
||||
Proto => Proto.into(),
|
||||
Timeout => Timeout.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Fail for Error {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
if let Some(ref backtrace) = self.backtrack {
|
||||
fmt::Display::fmt(&self.kind, f)?;
|
||||
fmt::Debug::fmt(backtrace, f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self.kind, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(kind: ErrorKind) -> Error {
|
||||
Error {
|
||||
inner: Context::new(kind),
|
||||
kind,
|
||||
backtrack: trace!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ErrorKind>> for Error {
|
||||
fn from(inner: Context<ErrorKind>) -> Error {
|
||||
Error { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for Error {
|
||||
fn from(msg: &'static str) -> Error {
|
||||
ErrorKind::Message(msg).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SendError> for Error {
|
||||
fn from(e: SendError) -> Self {
|
||||
e.context(ErrorKind::Message("error sending to mpsc"))
|
||||
.into()
|
||||
impl From<mpsc::SendError> for Error {
|
||||
fn from(e: mpsc::SendError) -> Self {
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,8 +123,8 @@ impl From<String> for Error {
|
||||
impl From<DnsSecError> for Error {
|
||||
fn from(e: DnsSecError) -> Error {
|
||||
match *e.kind() {
|
||||
DnsSecErrorKind::Timeout => e.context(ErrorKind::Timeout).into(),
|
||||
_ => e.context(ErrorKind::DnsSec).into(),
|
||||
DnsSecErrorKind::Timeout => ErrorKind::Timeout.into(),
|
||||
_ => ErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -160,8 +132,8 @@ impl From<DnsSecError> for Error {
|
||||
impl From<io::Error> for Error {
|
||||
fn from(e: io::Error) -> Self {
|
||||
match e.kind() {
|
||||
io::ErrorKind::TimedOut => e.context(ErrorKind::Timeout).into(),
|
||||
_ => e.context(ErrorKind::Io).into(),
|
||||
io::ErrorKind::TimedOut => ErrorKind::Timeout.into(),
|
||||
_ => ErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -169,8 +141,8 @@ impl From<io::Error> for Error {
|
||||
impl From<ProtoError> for Error {
|
||||
fn from(e: ProtoError) -> Error {
|
||||
match *e.kind() {
|
||||
ProtoErrorKind::Timeout => e.context(ErrorKind::Timeout).into(),
|
||||
_ => e.context(ErrorKind::Proto).into(),
|
||||
ProtoErrorKind::Timeout => ErrorKind::Timeout.into(),
|
||||
_ => ErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,8 +150,8 @@ impl From<ProtoError> for Error {
|
||||
impl From<Error> for io::Error {
|
||||
fn from(e: Error) -> Self {
|
||||
match *e.kind() {
|
||||
ErrorKind::Timeout => io::Error::new(io::ErrorKind::TimedOut, e.compat()),
|
||||
_ => io::Error::new(io::ErrorKind::Other, e.compat()),
|
||||
ErrorKind::Timeout => io::Error::new(io::ErrorKind::TimedOut, e),
|
||||
_ => io::Error::new(io::ErrorKind::Other, e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,14 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Benjamin Fry <benjaminfry@me.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
//! Dnssec error types for the crate
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
|
||||
#[cfg(not(feature = "openssl"))]
|
||||
use self::not_openssl::SslErrorStack;
|
||||
#[cfg(not(feature = "ring"))]
|
||||
@ -28,99 +17,98 @@ use self::not_ring::{KeyRejected, Unspecified};
|
||||
use openssl::error::ErrorStack as SslErrorStack;
|
||||
#[cfg(feature = "ring")]
|
||||
use ring::error::{KeyRejected, Unspecified};
|
||||
use thiserror::Error;
|
||||
use trust_dns_proto::error::{ProtoError, ProtoErrorKind};
|
||||
|
||||
use crate::proto::{trace, ExtBacktrace};
|
||||
|
||||
/// An alias for dnssec results returned by functions of this crate
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
/// The error kind for dnssec errors that get returned in the crate
|
||||
#[derive(Eq, PartialEq, Debug, Fail)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ErrorKind {
|
||||
/// An error with an arbitrary message, referenced as &'static str
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Message(&'static str),
|
||||
|
||||
/// An error with an arbitrary message, stored as String
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Msg(String),
|
||||
|
||||
// foreign
|
||||
/// An error got returned by the trust-dns-proto crate
|
||||
#[fail(display = "proto error")]
|
||||
Proto,
|
||||
#[error("proto error: {0}")]
|
||||
Proto(#[from] ProtoError),
|
||||
|
||||
/// A ring error
|
||||
#[fail(display = "ring error")]
|
||||
Ring,
|
||||
#[error("ring error: {0}")]
|
||||
RingKeyRejected(#[from] KeyRejected),
|
||||
|
||||
/// A ring error
|
||||
#[error("ring error: {0}")]
|
||||
RingUnspecified(#[from] Unspecified),
|
||||
|
||||
/// An ssl error
|
||||
#[fail(display = "ssl error")]
|
||||
SSL,
|
||||
#[error("ssl error: {0}")]
|
||||
SSL(#[from] SslErrorStack),
|
||||
|
||||
/// A request timed out
|
||||
#[fail(display = "request timed out")]
|
||||
#[error("request timed out")]
|
||||
Timeout,
|
||||
}
|
||||
|
||||
impl Clone for ErrorKind {
|
||||
fn clone(&self) -> Self {
|
||||
use self::ErrorKind::*;
|
||||
match *self {
|
||||
match self {
|
||||
Message(msg) => Message(msg),
|
||||
Msg(ref msg) => Msg(msg.clone()),
|
||||
|
||||
// foreign
|
||||
Proto => Proto,
|
||||
Ring => Ring,
|
||||
SSL => SSL,
|
||||
Proto(proto) => Proto(proto.clone()),
|
||||
RingKeyRejected(r) => Msg(format!("Ring rejected key: {}", r)),
|
||||
RingUnspecified(_r) => RingUnspecified(Unspecified),
|
||||
SSL(ssl) => Msg(format!("SSL had an error: {}", ssl)),
|
||||
Timeout => Timeout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The error type for dnssec errors that get returned in the crate
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone, Error)]
|
||||
pub struct Error {
|
||||
inner: Context<ErrorKind>,
|
||||
kind: ErrorKind,
|
||||
backtrack: Option<ExtBacktrace>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Get the kind of the error
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
self.inner.get_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl Fail for Error {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
if let Some(ref backtrace) = self.backtrack {
|
||||
fmt::Display::fmt(&self.kind, f)?;
|
||||
fmt::Debug::fmt(backtrace, f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self.kind, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(kind: ErrorKind) -> Error {
|
||||
Error {
|
||||
inner: Context::new(kind),
|
||||
kind,
|
||||
backtrack: trace!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ErrorKind>> for Error {
|
||||
fn from(inner: Context<ErrorKind>) -> Error {
|
||||
Error { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for Error {
|
||||
fn from(msg: &'static str) -> Error {
|
||||
ErrorKind::Message(msg).into()
|
||||
@ -136,27 +124,27 @@ impl From<String> for Error {
|
||||
impl From<ProtoError> for Error {
|
||||
fn from(e: ProtoError) -> Error {
|
||||
match *e.kind() {
|
||||
ProtoErrorKind::Timeout => e.context(ErrorKind::Timeout).into(),
|
||||
_ => e.context(ErrorKind::Proto).into(),
|
||||
ProtoErrorKind::Timeout => ErrorKind::Timeout.into(),
|
||||
_ => ErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KeyRejected> for Error {
|
||||
fn from(e: KeyRejected) -> Error {
|
||||
e.context(ErrorKind::Ring).into()
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Unspecified> for Error {
|
||||
fn from(e: Unspecified) -> Error {
|
||||
e.context(ErrorKind::Ring).into()
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SslErrorStack> for Error {
|
||||
fn from(e: SslErrorStack) -> Error {
|
||||
e.context(ErrorKind::SSL).into()
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,124 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Benjamin Fry <benjaminfry@me.com>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
//! Lexer error types for the crate
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::proto::{trace, ExtBacktrace};
|
||||
|
||||
/// An alias for lexer results returned by functions of this crate
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
/// The error kind for lexer errors that get returned in the crate
|
||||
#[derive(Eq, PartialEq, Debug, Fail)]
|
||||
#[derive(Eq, PartialEq, Debug, Error, Clone)]
|
||||
pub enum ErrorKind {
|
||||
/// Unexpected end of input
|
||||
#[fail(display = "unexpected end of input")]
|
||||
#[error("unexpected end of input")]
|
||||
EOF,
|
||||
|
||||
/// An illegal character was found
|
||||
#[fail(display = "illegal character input: {}", _0)]
|
||||
#[error("illegal character input: {0}")]
|
||||
IllegalCharacter(char),
|
||||
|
||||
/// An illegal state was reached
|
||||
#[fail(display = "illegal state: {}", _0)]
|
||||
#[error("illegal state: {0}")]
|
||||
IllegalState(&'static str),
|
||||
|
||||
/// An error with an arbitrary message, referenced as &'static str
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Message(&'static str),
|
||||
|
||||
/// An unclosed list was found
|
||||
#[fail(display = "unclosed list, missing ')'")]
|
||||
#[error("unclosed list, missing ')'")]
|
||||
UnclosedList,
|
||||
|
||||
/// An unclosed quoted string was found
|
||||
#[fail(display = "unclosed quoted string")]
|
||||
#[error("unclosed quoted string")]
|
||||
UnclosedQuotedString,
|
||||
|
||||
/// An unrecognized character was found
|
||||
#[fail(display = "unrecognized character input: {}", _0)]
|
||||
#[error("unrecognized character input: {0}")]
|
||||
UnrecognizedChar(char),
|
||||
|
||||
/// An unrecognized dollar content was found
|
||||
#[fail(display = "unrecognized dollar content: {}", _0)]
|
||||
#[error("unrecognized dollar content: {0}")]
|
||||
UnrecognizedDollar(String),
|
||||
|
||||
/// An unrecognized octet was found
|
||||
#[fail(display = "unrecognized octet: {:x}", _0)]
|
||||
#[error("unrecognized octet: {0:x}")]
|
||||
UnrecognizedOctet(u32),
|
||||
}
|
||||
|
||||
impl Clone for ErrorKind {
|
||||
fn clone(&self) -> Self {
|
||||
use self::ErrorKind::*;
|
||||
match *self {
|
||||
EOF => EOF,
|
||||
IllegalCharacter(c) => IllegalCharacter(c),
|
||||
IllegalState(s) => IllegalState(s),
|
||||
Message(msg) => Message(msg),
|
||||
UnclosedList => UnclosedList,
|
||||
UnclosedQuotedString => UnclosedQuotedString,
|
||||
UnrecognizedChar(c) => UnrecognizedChar(c),
|
||||
UnrecognizedDollar(ref s) => UnrecognizedDollar(s.clone()),
|
||||
UnrecognizedOctet(o) => UnrecognizedOctet(o),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The error type for lexer errors that get returned in the crate
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Error, Debug)]
|
||||
pub struct Error {
|
||||
inner: Context<ErrorKind>,
|
||||
kind: ErrorKind,
|
||||
backtrack: Option<ExtBacktrace>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Get the kind of the error
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
self.inner.get_context()
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(kind: ErrorKind) -> Error {
|
||||
Error {
|
||||
inner: Context::new(kind),
|
||||
kind,
|
||||
backtrack: trace!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ErrorKind>> for Error {
|
||||
fn from(inner: Context<ErrorKind>) -> Error {
|
||||
Error { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl Fail for Error {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
if let Some(ref backtrace) = self.backtrack {
|
||||
fmt::Display::fmt(&self.kind, f)?;
|
||||
fmt::Debug::fmt(backtrace, f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self.kind, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,155 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Benjamin Fry <benjaminfry@me.com>
|
||||
* Copyright (C) 2017 Google LLC.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
// Copyright (C) 2017 Google LLC.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
//! Parse error types for the crate
|
||||
|
||||
use std::{fmt, io};
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use thiserror::Error;
|
||||
use trust_dns_proto::error::{ProtoError, ProtoErrorKind};
|
||||
|
||||
use super::LexerError;
|
||||
use crate::proto::{trace, ExtBacktrace};
|
||||
use crate::serialize::txt::Token;
|
||||
|
||||
/// An alias for parse results returned by functions of this crate
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
/// The error kind for parse errors that get returned in the crate
|
||||
#[derive(Eq, PartialEq, Debug, Fail)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ErrorKind {
|
||||
/// An invalid numerical character was found
|
||||
#[fail(display = "invalid numerical character: {}", _0)]
|
||||
#[error("invalid numerical character: {0}")]
|
||||
CharToInt(char),
|
||||
|
||||
/// An error with an arbitrary message, referenced as &'static str
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Message(&'static str),
|
||||
|
||||
/// A token is missing
|
||||
#[fail(display = "token is missing: {}", _0)]
|
||||
#[error("token is missing: {0}")]
|
||||
MissingToken(String),
|
||||
|
||||
/// An error with an arbitrary message, stored as String
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Msg(String),
|
||||
|
||||
/// A time string could not be parsed
|
||||
#[fail(display = "invalid time string: {}", _0)]
|
||||
#[error("invalid time string: {0}")]
|
||||
ParseTime(String),
|
||||
|
||||
/// Found an unexpected token in a stream
|
||||
#[fail(display = "unrecognized token in stream: {:?}", _0)]
|
||||
#[error("unrecognized token in stream: {0:?}")]
|
||||
UnexpectedToken(Token),
|
||||
|
||||
// foreign
|
||||
/// An address parse error
|
||||
#[fail(display = "network address parse error")]
|
||||
AddrParse,
|
||||
#[error("network address parse error: {0}")]
|
||||
AddrParse(#[from] std::net::AddrParseError),
|
||||
|
||||
/// A data encoding error
|
||||
#[fail(display = "data encoding error")]
|
||||
DataEncoding,
|
||||
#[error("data encoding error: {0}")]
|
||||
DataEncoding(#[from] data_encoding::DecodeError),
|
||||
|
||||
/// An error got returned from IO
|
||||
#[fail(display = "io error")]
|
||||
Io,
|
||||
#[error("io error: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
/// An error from the lexer
|
||||
#[fail(display = "lexer error")]
|
||||
Lexer,
|
||||
#[error("lexer error: {0}")]
|
||||
Lexer(#[from] LexerError),
|
||||
|
||||
/// A number parsing error
|
||||
#[fail(display = "error parsing number")]
|
||||
ParseInt,
|
||||
#[error("error parsing number: {0}")]
|
||||
ParseInt(#[from] std::num::ParseIntError),
|
||||
|
||||
/// An error got returned by the trust-dns-proto crate
|
||||
#[fail(display = "proto error")]
|
||||
Proto,
|
||||
#[error("proto error: {0}")]
|
||||
Proto(#[from] ProtoError),
|
||||
|
||||
/// A request timed out
|
||||
#[fail(display = "request timed out")]
|
||||
#[error("request timed out")]
|
||||
Timeout,
|
||||
}
|
||||
|
||||
impl Clone for ErrorKind {
|
||||
fn clone(&self) -> Self {
|
||||
use self::ErrorKind::*;
|
||||
match *self {
|
||||
CharToInt(c) => CharToInt(c),
|
||||
match self {
|
||||
CharToInt(c) => CharToInt(*c),
|
||||
Message(msg) => Message(msg),
|
||||
MissingToken(ref s) => MissingToken(s.clone()),
|
||||
Msg(ref msg) => Msg(msg.clone()),
|
||||
ParseTime(ref s) => ParseTime(s.clone()),
|
||||
UnexpectedToken(ref token) => UnexpectedToken(token.clone()),
|
||||
|
||||
AddrParse => AddrParse,
|
||||
DataEncoding => DataEncoding,
|
||||
Io => Io,
|
||||
Lexer => Lexer,
|
||||
ParseInt => ParseInt,
|
||||
Proto => Proto,
|
||||
AddrParse(e) => AddrParse(e.clone()),
|
||||
DataEncoding(e) => DataEncoding(*e),
|
||||
Io(e) => Io(std::io::Error::from(e.kind())),
|
||||
Lexer(e) => Lexer(e.clone()),
|
||||
ParseInt(e) => ParseInt(e.clone()),
|
||||
Proto(e) => Proto(e.clone()),
|
||||
Timeout => Timeout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The error type for parse errors that get returned in the crate
|
||||
#[derive(Debug)]
|
||||
#[derive(Error, Debug)]
|
||||
pub struct Error {
|
||||
inner: Context<ErrorKind>,
|
||||
kind: ErrorKind,
|
||||
backtrack: Option<ExtBacktrace>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Get the kind of the error
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
self.inner.get_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl Fail for Error {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
if let Some(ref backtrace) = self.backtrack {
|
||||
fmt::Display::fmt(&self.kind, f)?;
|
||||
fmt::Debug::fmt(backtrace, f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self.kind, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(kind: ErrorKind) -> Error {
|
||||
Error {
|
||||
inner: Context::new(kind),
|
||||
kind,
|
||||
backtrack: trace!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ErrorKind>> for Error {
|
||||
fn from(inner: Context<ErrorKind>) -> Error {
|
||||
Error { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for Error {
|
||||
fn from(msg: &'static str) -> Error {
|
||||
ErrorKind::Message(msg).into()
|
||||
@ -162,44 +145,44 @@ impl From<String> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<::std::net::AddrParseError> for Error {
|
||||
fn from(e: ::std::net::AddrParseError) -> Error {
|
||||
e.context(ErrorKind::AddrParse).into()
|
||||
impl From<std::net::AddrParseError> for Error {
|
||||
fn from(e: std::net::AddrParseError) -> Error {
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<::data_encoding::DecodeError> for Error {
|
||||
fn from(e: ::data_encoding::DecodeError) -> Error {
|
||||
e.context(ErrorKind::DataEncoding).into()
|
||||
fn from(e: data_encoding::DecodeError) -> Error {
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(e: io::Error) -> Error {
|
||||
match e.kind() {
|
||||
io::ErrorKind::TimedOut => e.context(ErrorKind::Timeout).into(),
|
||||
_ => e.context(ErrorKind::Io).into(),
|
||||
io::ErrorKind::TimedOut => ErrorKind::Timeout.into(),
|
||||
_ => ErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LexerError> for Error {
|
||||
fn from(e: LexerError) -> Error {
|
||||
e.context(ErrorKind::Lexer).into()
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<::std::num::ParseIntError> for Error {
|
||||
fn from(e: ::std::num::ParseIntError) -> Error {
|
||||
e.context(ErrorKind::ParseInt).into()
|
||||
impl From<std::num::ParseIntError> for Error {
|
||||
fn from(e: std::num::ParseIntError) -> Error {
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProtoError> for Error {
|
||||
fn from(e: ProtoError) -> Error {
|
||||
match *e.kind() {
|
||||
ProtoErrorKind::Timeout => e.context(ErrorKind::Timeout).into(),
|
||||
_ => e.context(ErrorKind::Proto).into(),
|
||||
ProtoErrorKind::Timeout => ErrorKind::Timeout.into(),
|
||||
_ => ErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -207,8 +190,8 @@ impl From<ProtoError> for Error {
|
||||
impl From<Error> for io::Error {
|
||||
fn from(e: Error) -> Self {
|
||||
match *e.kind() {
|
||||
ErrorKind::Timeout => io::Error::new(io::ErrorKind::TimedOut, e.compat()),
|
||||
_ => io::Error::new(io::ErrorKind::Other, e.compat()),
|
||||
ErrorKind::Timeout => io::Error::new(io::ErrorKind::TimedOut, e),
|
||||
_ => io::Error::new(io::ErrorKind::Other, e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,14 +47,15 @@ name = "trust_dns_https"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
backtrace = "0.3.40"
|
||||
bytes = "0.5"
|
||||
data-encoding = "2.1.0"
|
||||
failure = "0.1"
|
||||
futures = "0.3.0"
|
||||
h2 = { version = "0.2.0", features = ["stream"] }
|
||||
http = "0.2"
|
||||
log = "0.4"
|
||||
rustls = "0.16"
|
||||
thiserror = "1.0.9"
|
||||
tokio = { version = "0.2.1", features = ["tcp", "io-util", "rt-core"] }
|
||||
tokio-rustls = "0.12.1"
|
||||
# disables default features, i.e. openssl...
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2018 Benjamin Fry <benjaminfry@me.com>
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
@ -7,77 +7,70 @@
|
||||
|
||||
use std::{fmt, io};
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use h2;
|
||||
use thiserror::Error;
|
||||
use trust_dns_proto::error::ProtoError;
|
||||
use typed_headers;
|
||||
|
||||
use crate::proto::{trace, ExtBacktrace};
|
||||
|
||||
/// An alias for results returned by functions of this crate
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ErrorKind {
|
||||
/// An error with an arbitrary message, referenced as &'static str
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Message(&'static str),
|
||||
|
||||
/// An error with an arbitrary message, stored as String
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Msg(String),
|
||||
|
||||
#[fail(display = "proto error: {}", _0)]
|
||||
ProtoError(ProtoError),
|
||||
#[error("proto error: {0}")]
|
||||
ProtoError(#[from] ProtoError),
|
||||
|
||||
#[fail(display = "bad header: {}", _0)]
|
||||
TypedHeaders(typed_headers::Error),
|
||||
#[error("bad header: {0}")]
|
||||
TypedHeaders(#[from] typed_headers::Error),
|
||||
|
||||
#[fail(display = "h2: {}", _0)]
|
||||
H2(h2::Error),
|
||||
#[error("h2: {0}")]
|
||||
H2(#[from] h2::Error),
|
||||
}
|
||||
|
||||
/// The error type for errors that get returned in the crate
|
||||
#[derive(Debug)]
|
||||
pub struct Error {
|
||||
inner: Context<ErrorKind>,
|
||||
kind: ErrorKind,
|
||||
backtrack: Option<ExtBacktrace>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Get the kind of the error
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
self.inner.get_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl Fail for Error {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
if let Some(ref backtrace) = self.backtrack {
|
||||
fmt::Display::fmt(&self.kind, f)?;
|
||||
fmt::Debug::fmt(backtrace, f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self.kind, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(kind: ErrorKind) -> Error {
|
||||
Error {
|
||||
inner: Context::new(kind),
|
||||
kind,
|
||||
backtrack: trace!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ErrorKind>> for Error {
|
||||
fn from(inner: Context<ErrorKind>) -> Error {
|
||||
Error { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for Error {
|
||||
fn from(msg: &'static str) -> Error {
|
||||
ErrorKind::Message(msg).into()
|
||||
|
@ -15,10 +15,11 @@ use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use futures::{future, Future, FutureExt, Stream, TryFutureExt};
|
||||
use futures::{future, ready, Future, FutureExt, Stream, TryFutureExt};
|
||||
use h2;
|
||||
use h2::client::{Connection, SendRequest};
|
||||
use http::{self, header};
|
||||
use log::{debug, warn};
|
||||
use rustls::ClientConfig;
|
||||
use tokio;
|
||||
use tokio::net::TcpStream as TokioTcpStream;
|
||||
|
@ -15,6 +15,7 @@ use bytes::{Bytes, BytesMut};
|
||||
use futures::{Stream, StreamExt};
|
||||
use h2;
|
||||
use http::{Method, Request};
|
||||
use log::debug;
|
||||
use typed_headers::{ContentLength, HeaderMapExt};
|
||||
|
||||
use crate::HttpsError;
|
||||
|
@ -13,24 +13,6 @@
|
||||
clippy::unimplemented
|
||||
)]
|
||||
|
||||
extern crate bytes;
|
||||
extern crate data_encoding;
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
extern crate h2;
|
||||
extern crate http;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate failure;
|
||||
extern crate rustls;
|
||||
extern crate tokio;
|
||||
extern crate tokio_rustls;
|
||||
extern crate trust_dns_proto;
|
||||
extern crate trust_dns_rustls;
|
||||
extern crate typed_headers;
|
||||
extern crate webpki;
|
||||
extern crate webpki_roots;
|
||||
|
||||
const MIME_APPLICATION: &str = "application";
|
||||
const MIME_DNS_BINARY: &str = "dns-message";
|
||||
const MIME_APPLICATION_DNS: &str = "application/dns-message";
|
||||
@ -44,6 +26,8 @@ pub mod request;
|
||||
pub mod response;
|
||||
//pub mod https_stream;
|
||||
|
||||
pub use trust_dns_proto as proto;
|
||||
|
||||
pub use self::error::{Error as HttpsError, Result as HttpsResult};
|
||||
|
||||
//pub use self::https_client_connection::{HttpsClientConnection, HttpsClientConnectionBuilder};
|
||||
|
@ -10,6 +10,7 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use http::{header, uri, Method, Request, Uri, Version};
|
||||
use log::debug;
|
||||
use typed_headers::{
|
||||
mime::Mime, Accept, ContentLength, ContentType, HeaderMapExt, Quality, QualityItem,
|
||||
};
|
||||
|
@ -57,9 +57,9 @@ path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1.22"
|
||||
backtrace = "0.3.40"
|
||||
data-encoding = { version = "2.1.0", optional = true }
|
||||
enum-as-inner = "0.3"
|
||||
failure = "0.1"
|
||||
futures = "0.3.0"
|
||||
idna = "0.2.0"
|
||||
lazy_static = "1.0"
|
||||
@ -70,6 +70,7 @@ ring = { version = "0.16", optional = true, features = ["std"] }
|
||||
serde = { version = "1.0", optional = true }
|
||||
smallvec = "1.0"
|
||||
socket2 = { version = "0.3.10", optional = true }
|
||||
thiserror = "1.0.9"
|
||||
tokio = { version = "0.2.1", optional = true }
|
||||
url = "2.1.0"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2017 Benjamin Fry <benjaminfry@me.com>
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
@ -11,31 +11,60 @@
|
||||
|
||||
use std::{fmt, io, sync};
|
||||
|
||||
use crate::rr::{Name, RecordType};
|
||||
|
||||
#[cfg(not(feature = "openssl"))]
|
||||
use self::not_openssl::SslErrorStack;
|
||||
#[cfg(not(feature = "ring"))]
|
||||
use self::not_ring::Unspecified;
|
||||
pub use backtrace::Backtrace as ExtBacktrace;
|
||||
use lazy_static::lazy_static;
|
||||
#[cfg(feature = "openssl")]
|
||||
use openssl::error::ErrorStack as SslErrorStack;
|
||||
#[cfg(feature = "ring")]
|
||||
use ring::error::Unspecified;
|
||||
use thiserror::Error;
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use crate::rr::{Name, RecordType};
|
||||
|
||||
lazy_static! {
|
||||
/// Boolean for checking if backtrace is enabled at runtime
|
||||
pub static ref ENABLE_BACKTRACE: bool = {
|
||||
use std::env;
|
||||
let bt = env::var("RUST_BACKTRACE");
|
||||
match bt.as_ref().map(|s| s as &str) {
|
||||
Ok("full") | Ok("1") => true,
|
||||
_ => false,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Generate a backtrace
|
||||
///
|
||||
/// If RUST_BACKTRACE is 1 or full then this will return Some(Backtrace), otherwise, NONE.
|
||||
#[macro_export]
|
||||
macro_rules! trace {
|
||||
() => {{
|
||||
use $crate::error::ExtBacktrace as Backtrace;
|
||||
|
||||
if *$crate::error::ENABLE_BACKTRACE {
|
||||
Some(Backtrace::new())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
/// An alias for results returned by functions of this crate
|
||||
pub type ProtoResult<T> = ::std::result::Result<T, ProtoError>;
|
||||
|
||||
/// The error kind for errors that get returned in the crate
|
||||
#[derive(Eq, PartialEq, Debug, Fail)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ProtoErrorKind {
|
||||
/// An error caused by a canceled future
|
||||
#[fail(display = "future was canceled: {:?}", _0)]
|
||||
#[error("future was canceled: {0:?}")]
|
||||
Canceled(futures::channel::oneshot::Canceled),
|
||||
|
||||
/// Character data length exceeded the limit
|
||||
#[fail(display = "char data length exceeds {}: {}", _0, _1)]
|
||||
#[error("char data length exceeds {max}: {len}")]
|
||||
CharacterDataTooLong {
|
||||
/// Specified maximum
|
||||
max: usize,
|
||||
@ -44,7 +73,7 @@ pub enum ProtoErrorKind {
|
||||
},
|
||||
|
||||
/// Overlapping labels
|
||||
#[fail(display = "overlapping labels name {} other {}", _0, _1)]
|
||||
#[error("overlapping labels name {label} other {other}")]
|
||||
LabelOverlapsWithOther {
|
||||
/// Start of the label that is overlaps
|
||||
label: usize,
|
||||
@ -53,22 +82,19 @@ pub enum ProtoErrorKind {
|
||||
},
|
||||
|
||||
/// DNS protocol version doesn't have the expected version 3
|
||||
#[fail(display = "dns key value unknown, must be 3: {}", _0)]
|
||||
#[error("dns key value unknown, must be 3: {0}")]
|
||||
DnsKeyProtocolNot3(u8),
|
||||
|
||||
/// A domain name was too long
|
||||
#[fail(display = "name label data exceed 255: {}", _0)]
|
||||
#[error("name label data exceed 255: {0}")]
|
||||
DomainNameTooLong(usize),
|
||||
|
||||
/// EDNS resource record label is not the root label, although required
|
||||
#[fail(
|
||||
display = "edns resource record label must be the root label (.): {}",
|
||||
_0
|
||||
)]
|
||||
#[error("edns resource record label must be the root label (.): {0}")]
|
||||
EdnsNameNotRoot(crate::rr::Name),
|
||||
|
||||
/// The length of rdata read was not as expected
|
||||
#[fail(display = "incorrect rdata length read: {} expected: {}", read, len)]
|
||||
#[error("incorrect rdata length read: {read} expected: {len}")]
|
||||
IncorrectRDataLengthRead {
|
||||
/// The amount of read data
|
||||
read: usize,
|
||||
@ -77,11 +103,11 @@ pub enum ProtoErrorKind {
|
||||
},
|
||||
|
||||
/// Label bytes exceeded the limit of 63
|
||||
#[fail(display = "label bytes exceed 63: {}", _0)]
|
||||
#[error("label bytes exceed 63: {0}")]
|
||||
LabelBytesTooLong(usize),
|
||||
|
||||
/// Label bytes exceeded the limit of 63
|
||||
#[fail(display = "label points to data not prior to idx: {} ptr: {}", _0, _1)]
|
||||
#[error("label points to data not prior to idx: {idx} ptr: {ptr}")]
|
||||
PointerNotPriorToLabel {
|
||||
/// index of the label containing this pointer
|
||||
idx: usize,
|
||||
@ -90,33 +116,30 @@ pub enum ProtoErrorKind {
|
||||
},
|
||||
|
||||
/// The maximum buffer size was exceeded
|
||||
#[fail(display = "maximum buffer size exceeded: {}", _0)]
|
||||
#[error("maximum buffer size exceeded: {0}")]
|
||||
MaxBufferSizeExceeded(usize),
|
||||
|
||||
/// An error with an arbitrary message, referenced as &'static str
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Message(&'static str),
|
||||
|
||||
/// An error with an arbitrary message, stored as String
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Msg(String),
|
||||
|
||||
/// No error was specified
|
||||
#[fail(display = "no error specified")]
|
||||
#[error("no error specified")]
|
||||
NoError,
|
||||
|
||||
/// Not all records were able to be written
|
||||
#[fail(display = "not all records could be written, wrote: {}", count)]
|
||||
#[error("not all records could be written, wrote: {count}")]
|
||||
NotAllRecordsWritten {
|
||||
/// Number of records that were written before the error
|
||||
count: usize,
|
||||
},
|
||||
|
||||
/// Missing rrsigs
|
||||
#[fail(
|
||||
display = "rrsigs are not present for record set name: {} record_type: {}",
|
||||
name, record_type
|
||||
)]
|
||||
#[error("rrsigs are not present for record set name: {name} record_type: {record_type}")]
|
||||
RrsigsNotPresent {
|
||||
/// The record set name
|
||||
name: Name,
|
||||
@ -125,118 +148,101 @@ pub enum ProtoErrorKind {
|
||||
},
|
||||
|
||||
/// An unknown algorithm type was found
|
||||
#[fail(display = "algorithm type value unknown: {}", _0)]
|
||||
#[error("algorithm type value unknown: {0}")]
|
||||
UnknownAlgorithmTypeValue(u8),
|
||||
|
||||
/// An unknown dns class was found
|
||||
#[fail(display = "dns class string unknown: {}", _0)]
|
||||
#[error("dns class string unknown: {0}")]
|
||||
UnknownDnsClassStr(String),
|
||||
|
||||
/// An unknown dns class value was found
|
||||
#[fail(display = "dns class value unknown: {}", _0)]
|
||||
#[error("dns class value unknown: {0}")]
|
||||
UnknownDnsClassValue(u16),
|
||||
|
||||
/// An unknown record type string was found
|
||||
#[fail(display = "record type string unknown: {}", _0)]
|
||||
#[error("record type string unknown: {0}")]
|
||||
UnknownRecordTypeStr(String),
|
||||
|
||||
/// An unknown record type value was found
|
||||
#[fail(display = "record type value unknown: {}", _0)]
|
||||
#[error("record type value unknown: {0}")]
|
||||
UnknownRecordTypeValue(u16),
|
||||
|
||||
/// An unrecognized label code was found
|
||||
#[fail(display = "unrecognized label code: {:b}", _0)]
|
||||
#[error("unrecognized label code: {0:b}")]
|
||||
UnrecognizedLabelCode(u8),
|
||||
|
||||
/// Unrecognized nsec3 flags were found
|
||||
#[fail(display = "nsec3 flags should be 0b0000000*: {:b}", _0)]
|
||||
#[error("nsec3 flags should be 0b0000000*: {0:b}")]
|
||||
UnrecognizedNsec3Flags(u8),
|
||||
|
||||
// foreign
|
||||
/// An error got returned from IO
|
||||
#[fail(display = "io error")]
|
||||
Io,
|
||||
#[error("io error: {0}")]
|
||||
Io(#[from] io::Error),
|
||||
|
||||
/// Any sync poised error
|
||||
#[fail(display = "lock poisoned error")]
|
||||
#[error("lock poisoned error")]
|
||||
Poisoned,
|
||||
|
||||
/// A ring error
|
||||
#[fail(display = "ring error")]
|
||||
Ring,
|
||||
#[error("ring error: {0}")]
|
||||
Ring(#[from] Unspecified),
|
||||
|
||||
/// An ssl error
|
||||
#[fail(display = "ssl error")]
|
||||
SSL,
|
||||
#[error("ssl error: {0}")]
|
||||
SSL(#[from] SslErrorStack),
|
||||
|
||||
/// A tokio timer error
|
||||
#[fail(display = "timer error")]
|
||||
#[error("timer error")]
|
||||
Timer,
|
||||
|
||||
/// A request timed out
|
||||
#[fail(display = "request timed out")]
|
||||
#[error("request timed out")]
|
||||
Timeout,
|
||||
|
||||
/// An url parsing error
|
||||
#[fail(display = "url parsing error")]
|
||||
UrlParsing,
|
||||
#[error("url parsing error")]
|
||||
UrlParsing(#[from] url::ParseError),
|
||||
|
||||
/// A utf8 parsing error
|
||||
#[fail(display = "error parsing utf8 string")]
|
||||
Utf8,
|
||||
#[error("error parsing utf8 string")]
|
||||
Utf8(#[from] std::str::Utf8Error),
|
||||
}
|
||||
|
||||
/// The error type for errors that get returned in the crate
|
||||
#[derive(Debug)]
|
||||
#[derive(Error, Clone, Debug)]
|
||||
pub struct ProtoError {
|
||||
inner: Context<ProtoErrorKind>,
|
||||
kind: ProtoErrorKind,
|
||||
backtrack: Option<ExtBacktrace>,
|
||||
}
|
||||
|
||||
impl ProtoError {
|
||||
/// Get the kind of the error
|
||||
pub fn kind(&self) -> &ProtoErrorKind {
|
||||
self.inner.get_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for ProtoError {
|
||||
fn clone(&self) -> Self {
|
||||
ProtoError {
|
||||
inner: Context::new(self.inner.get_context().clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Fail for ProtoError {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ProtoError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
if let Some(ref backtrace) = self.backtrack {
|
||||
fmt::Display::fmt(&self.kind, f)?;
|
||||
fmt::Debug::fmt(backtrace, f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self.kind, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProtoErrorKind> for ProtoError {
|
||||
fn from(kind: ProtoErrorKind) -> ProtoError {
|
||||
ProtoError {
|
||||
inner: Context::new(kind),
|
||||
kind,
|
||||
backtrack: trace!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ProtoErrorKind>> for ProtoError {
|
||||
fn from(inner: Context<ProtoErrorKind>) -> ProtoError {
|
||||
ProtoError { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for ProtoError {
|
||||
fn from(msg: &'static str) -> ProtoError {
|
||||
ProtoErrorKind::Message(msg).into()
|
||||
@ -252,39 +258,39 @@ impl From<String> for ProtoError {
|
||||
impl From<io::Error> for ProtoError {
|
||||
fn from(e: io::Error) -> ProtoError {
|
||||
match e.kind() {
|
||||
io::ErrorKind::TimedOut => e.context(ProtoErrorKind::Timeout).into(),
|
||||
_ => e.context(ProtoErrorKind::Io).into(),
|
||||
io::ErrorKind::TimedOut => ProtoErrorKind::Timeout.into(),
|
||||
_ => ProtoErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<sync::PoisonError<T>> for ProtoError {
|
||||
fn from(_e: sync::PoisonError<T>) -> ProtoError {
|
||||
Context::new(ProtoErrorKind::Poisoned).into()
|
||||
ProtoErrorKind::Poisoned.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Unspecified> for ProtoError {
|
||||
fn from(e: Unspecified) -> ProtoError {
|
||||
e.context(ProtoErrorKind::Ring).into()
|
||||
ProtoErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SslErrorStack> for ProtoError {
|
||||
fn from(e: SslErrorStack) -> ProtoError {
|
||||
e.context(ProtoErrorKind::SSL).into()
|
||||
ProtoErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<::url::ParseError> for ProtoError {
|
||||
fn from(e: ::url::ParseError) -> ProtoError {
|
||||
e.context(ProtoErrorKind::UrlParsing).into()
|
||||
impl From<url::ParseError> for ProtoError {
|
||||
fn from(e: url::ParseError) -> ProtoError {
|
||||
ProtoErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<::std::str::Utf8Error> for ProtoError {
|
||||
fn from(e: ::std::str::Utf8Error) -> ProtoError {
|
||||
e.context(ProtoErrorKind::Utf8).into()
|
||||
impl From<std::str::Utf8Error> for ProtoError {
|
||||
fn from(e: std::str::Utf8Error) -> ProtoError {
|
||||
ProtoErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,8 +341,8 @@ pub mod not_ring {
|
||||
impl From<ProtoError> for io::Error {
|
||||
fn from(e: ProtoError) -> Self {
|
||||
match *e.kind() {
|
||||
ProtoErrorKind::Timeout => io::Error::new(io::ErrorKind::TimedOut, e.compat()),
|
||||
_ => io::Error::new(io::ErrorKind::Other, e.compat()),
|
||||
ProtoErrorKind::Timeout => io::Error::new(io::ErrorKind::TimedOut, e),
|
||||
_ => io::Error::new(io::ErrorKind::Other, e),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -381,21 +387,20 @@ impl Clone for ProtoErrorKind {
|
||||
UnrecognizedNsec3Flags(flags) => UnrecognizedNsec3Flags(flags),
|
||||
|
||||
// foreign
|
||||
Io => Io,
|
||||
Io(ref e) => Io(io::Error::from(e.kind())),
|
||||
Poisoned => Poisoned,
|
||||
Ring => Ring,
|
||||
SSL => SSL,
|
||||
Ring(ref _e) => Ring(Unspecified),
|
||||
SSL(ref e) => Msg(format!("there was an SSL error: {}", e)),
|
||||
Timeout => Timeout,
|
||||
Timer => Timer,
|
||||
UrlParsing => UrlParsing,
|
||||
Utf8 => Utf8,
|
||||
UrlParsing(ref e) => UrlParsing(*e),
|
||||
Utf8(ref e) => Utf8(*e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait marking a type which implements From<ProtoError> and
|
||||
/// failure::Fail (which includes all std::error::Error types)
|
||||
/// as well as Clone + Send
|
||||
pub trait FromProtoError: From<ProtoError> + Fail + Clone {}
|
||||
/// std::error::Error types as well as Clone + Send
|
||||
pub trait FromProtoError: From<ProtoError> + std::error::Error + Clone {}
|
||||
|
||||
impl<E> FromProtoError for E where E: From<ProtoError> + Fail + Clone {}
|
||||
impl<E> FromProtoError for E where E: From<ProtoError> + std::error::Error + Clone {}
|
||||
|
@ -69,6 +69,7 @@ pub use crate::xfer::dnssec_dns_handle::DnssecDnsHandle;
|
||||
pub use crate::xfer::retry_dns_handle::RetryDnsHandle;
|
||||
#[doc(hidden)]
|
||||
pub use crate::xfer::{BufDnsStreamHandle, BufStreamHandle};
|
||||
pub use error::ExtBacktrace;
|
||||
|
||||
#[cfg(feature = "tokio-runtime")]
|
||||
#[doc(hidden)]
|
||||
|
@ -64,8 +64,8 @@ name = "trust_dns_resolver"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
backtrace = "0.3.40"
|
||||
cfg-if = "0.1.9"
|
||||
failure = "0.1"
|
||||
futures = "0.3.0"
|
||||
lazy_static = "1.0"
|
||||
log = "0.4"
|
||||
@ -74,6 +74,7 @@ resolv-conf = { version = "0.6.0", features = ["system"] }
|
||||
rustls = {version = "0.16", optional = true}
|
||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||
smallvec = "1.0"
|
||||
thiserror = "1.0.9"
|
||||
tokio = { version = "0.2.1", optional = true }
|
||||
tokio-tls = { version = "0.3.0", optional = true }
|
||||
tokio-openssl = { version = "0.4.0", optional = true }
|
||||
|
@ -613,7 +613,6 @@ pub mod testing {
|
||||
<<R as RuntimeProvider>::Tcp as Connect>::Transport: Unpin,
|
||||
{
|
||||
use crate::error::*;
|
||||
use failure::Fail;
|
||||
use proto::rr::RecordType;
|
||||
let resolver = AsyncResolver::<GenericConnection, GenericConnectionProvider<R>>::new(
|
||||
ResolverConfig::default(),
|
||||
@ -635,7 +634,7 @@ pub mod testing {
|
||||
|
||||
use proto::error::{ProtoError, ProtoErrorKind};
|
||||
|
||||
let error_str = format!("{}", error.root_cause());
|
||||
let error_str = format!("{}", error);
|
||||
let expected_str = format!(
|
||||
"{}",
|
||||
ProtoError::from(ProtoErrorKind::RrsigsNotPresent {
|
||||
@ -644,7 +643,10 @@ pub mod testing {
|
||||
})
|
||||
);
|
||||
assert_eq!(error_str, expected_str);
|
||||
assert_eq!(*error.kind(), ResolveErrorKind::Proto);
|
||||
if let ResolveErrorKind::Proto(_) = *error.kind() {
|
||||
} else {
|
||||
panic!("wrong error")
|
||||
}
|
||||
}
|
||||
|
||||
/// Test AsyncResolver created from system configuration with IP lookup.
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2017 Benjamin Fry <benjaminfry@me.com>
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
@ -7,27 +7,30 @@
|
||||
|
||||
//! Error types for the crate
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use proto::error::{ProtoError, ProtoErrorKind};
|
||||
use proto::op::Query;
|
||||
use std::{fmt, io, sync, time::Instant};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::proto::error::{ProtoError, ProtoErrorKind};
|
||||
use crate::proto::op::Query;
|
||||
use crate::proto::{trace, ExtBacktrace};
|
||||
|
||||
/// An alias for results returned by functions of this crate
|
||||
pub type ResolveResult<T> = ::std::result::Result<T, ResolveError>;
|
||||
|
||||
/// The error kind for errors that get returned in the crate
|
||||
#[derive(Eq, PartialEq, Debug, Fail)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ResolveErrorKind {
|
||||
/// An error with an arbitrary message, referenced as &'static str
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Message(&'static str),
|
||||
|
||||
/// An error with an arbitrary message, stored as String
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{0}")]
|
||||
Msg(String),
|
||||
|
||||
/// No records were found for a query
|
||||
#[fail(display = "no record found for {}", query)]
|
||||
#[error("no record found for {query}")]
|
||||
NoRecordsFound {
|
||||
/// The query for which no records were found.
|
||||
query: Query,
|
||||
@ -38,22 +41,22 @@ pub enum ResolveErrorKind {
|
||||
|
||||
// foreign
|
||||
/// An error got returned from IO
|
||||
#[fail(display = "io error")]
|
||||
Io,
|
||||
#[error("io error: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
/// An error got returned by the trust-dns-proto crate
|
||||
#[fail(display = "proto error")]
|
||||
Proto,
|
||||
#[error("proto error: {0}")]
|
||||
Proto(#[from] ProtoError),
|
||||
|
||||
/// A request timed out
|
||||
#[fail(display = "request timed out")]
|
||||
#[error("request timed out")]
|
||||
Timeout,
|
||||
}
|
||||
|
||||
impl Clone for ResolveErrorKind {
|
||||
fn clone(&self) -> Self {
|
||||
use self::ResolveErrorKind::*;
|
||||
match *self {
|
||||
match self {
|
||||
Message(msg) => Message(msg),
|
||||
Msg(ref msg) => Msg(msg.clone()),
|
||||
NoRecordsFound {
|
||||
@ -61,68 +64,51 @@ impl Clone for ResolveErrorKind {
|
||||
valid_until,
|
||||
} => NoRecordsFound {
|
||||
query: query.clone(),
|
||||
valid_until,
|
||||
valid_until: *valid_until,
|
||||
},
|
||||
|
||||
// foreign
|
||||
Io => Io,
|
||||
Proto => Proto,
|
||||
Io(io) => ResolveErrorKind::from(std::io::Error::from(io.kind())),
|
||||
Proto(proto) => ResolveErrorKind::from(proto.clone()),
|
||||
Timeout => Timeout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The error type for errors that get returned in the crate
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone, Error)]
|
||||
pub struct ResolveError {
|
||||
inner: Context<ResolveErrorKind>,
|
||||
kind: ResolveErrorKind,
|
||||
backtrack: Option<ExtBacktrace>,
|
||||
}
|
||||
|
||||
impl ResolveError {
|
||||
/// Get the kind of the error
|
||||
pub fn kind(&self) -> &ResolveErrorKind {
|
||||
self.inner.get_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for ResolveError {
|
||||
fn clone(&self) -> Self {
|
||||
ResolveError {
|
||||
inner: Context::new(self.inner.get_context().clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Fail for ResolveError {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ResolveError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
if let Some(ref backtrace) = self.backtrack {
|
||||
fmt::Display::fmt(&self.kind, f)?;
|
||||
fmt::Debug::fmt(backtrace, f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self.kind, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ResolveErrorKind> for ResolveError {
|
||||
fn from(kind: ResolveErrorKind) -> ResolveError {
|
||||
ResolveError {
|
||||
inner: Context::new(kind),
|
||||
kind,
|
||||
backtrack: trace!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ResolveErrorKind>> for ResolveError {
|
||||
fn from(inner: Context<ResolveErrorKind>) -> ResolveError {
|
||||
ResolveError { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for ResolveError {
|
||||
fn from(msg: &'static str) -> ResolveError {
|
||||
ResolveErrorKind::Message(msg).into()
|
||||
@ -132,8 +118,7 @@ impl From<&'static str> for ResolveError {
|
||||
#[cfg(target_os = "windows")]
|
||||
impl From<ipconfig::error::Error> for ResolveError {
|
||||
fn from(e: ipconfig::error::Error) -> ResolveError {
|
||||
e.context(ResolveErrorKind::Message("failed to read from registry"))
|
||||
.into()
|
||||
ResolveErrorKind::Msg(format!("failed to read from registry: {}", e)).into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,8 +131,8 @@ impl From<String> for ResolveError {
|
||||
impl From<io::Error> for ResolveError {
|
||||
fn from(e: io::Error) -> ResolveError {
|
||||
match e.kind() {
|
||||
io::ErrorKind::TimedOut => e.context(ResolveErrorKind::Timeout).into(),
|
||||
_ => e.context(ResolveErrorKind::Io).into(),
|
||||
io::ErrorKind::TimedOut => ResolveErrorKind::Timeout.into(),
|
||||
_ => ResolveErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -155,17 +140,17 @@ impl From<io::Error> for ResolveError {
|
||||
impl From<ProtoError> for ResolveError {
|
||||
fn from(e: ProtoError) -> ResolveError {
|
||||
match *e.kind() {
|
||||
ProtoErrorKind::Timeout => e.context(ResolveErrorKind::Timeout).into(),
|
||||
_ => e.context(ResolveErrorKind::Proto).into(),
|
||||
ProtoErrorKind::Timeout => ResolveErrorKind::Timeout.into(),
|
||||
_ => ResolveErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ResolveError> for io::Error {
|
||||
fn from(e: ResolveError) -> Self {
|
||||
match *e.kind() {
|
||||
ResolveErrorKind::Timeout => io::Error::new(io::ErrorKind::TimedOut, e.compat()),
|
||||
_ => io::Error::new(io::ErrorKind::Other, e.compat()),
|
||||
match e.kind() {
|
||||
ResolveErrorKind::Timeout => io::Error::new(io::ErrorKind::TimedOut, e),
|
||||
_ => io::Error::new(io::ErrorKind::Other, e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +194,6 @@
|
||||
#[cfg(feature = "dns-over-tls")]
|
||||
#[macro_use]
|
||||
extern crate cfg_if;
|
||||
extern crate failure;
|
||||
extern crate futures;
|
||||
#[cfg(target_os = "windows")]
|
||||
extern crate ipconfig;
|
||||
|
@ -541,7 +541,7 @@ pub mod tests {
|
||||
}
|
||||
|
||||
pub fn error() -> ProtoResult<DnsResponse> {
|
||||
Err(ProtoErrorKind::Io.into())
|
||||
Err(ProtoErrorKind::from(std::io::Error::from(std::io::ErrorKind::Other)).into())
|
||||
}
|
||||
|
||||
pub fn mock(messages: Vec<ProtoResult<DnsResponse>>) -> MockDnsHandle {
|
||||
@ -597,20 +597,21 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_empty_no_response() {
|
||||
assert_eq!(
|
||||
*block_on(LookupFuture::lookup(
|
||||
if let ResolveErrorKind::NoRecordsFound { query, valid_until } =
|
||||
block_on(LookupFuture::lookup(
|
||||
vec![Name::root()],
|
||||
RecordType::A,
|
||||
DnsRequestOptions::default(),
|
||||
CachingClient::new(0, mock(vec![empty()])),
|
||||
))
|
||||
.unwrap_err()
|
||||
.kind(),
|
||||
ResolveErrorKind::NoRecordsFound {
|
||||
query: Query::query(Name::root(), RecordType::A),
|
||||
valid_until: None,
|
||||
}
|
||||
);
|
||||
.kind()
|
||||
{
|
||||
assert_eq!(*query, Query::query(Name::root(), RecordType::A));
|
||||
assert_eq!(*valid_until, None);
|
||||
} else {
|
||||
panic!("wrong error recieved");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -425,19 +425,17 @@ mod tests {
|
||||
let client = mock(vec![empty()]);
|
||||
let client = CachingClient::with_cache(cache, client);
|
||||
|
||||
assert_eq!(
|
||||
*block_on(CachingClient::inner_lookup(
|
||||
Query::new(),
|
||||
Default::default(),
|
||||
client,
|
||||
))
|
||||
.unwrap_err()
|
||||
.kind(),
|
||||
ResolveErrorKind::NoRecordsFound {
|
||||
query: Query::new(),
|
||||
valid_until: None,
|
||||
}
|
||||
);
|
||||
if let ResolveErrorKind::NoRecordsFound { query, valid_until } = block_on(
|
||||
CachingClient::inner_lookup(Query::new(), Default::default(), client),
|
||||
)
|
||||
.unwrap_err()
|
||||
.kind()
|
||||
{
|
||||
assert_eq!(*query, Query::new());
|
||||
assert_eq!(*valid_until, None);
|
||||
} else {
|
||||
panic!("wrong error received")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -70,11 +70,11 @@ name = "trust_dns_server"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
backtrace = "0.3.40"
|
||||
bytes = "0.5"
|
||||
chrono = "0.4"
|
||||
enum-as-inner = "0.3"
|
||||
env_logger = "0.7"
|
||||
failure = "0.1"
|
||||
futures = "0.3.0"
|
||||
h2 = { version = "0.2.0", features = ["stream"], optional = true }
|
||||
http = { version = "0.2", optional = true }
|
||||
@ -83,6 +83,7 @@ openssl = { version = "0.10", features = ["v102", "v110"], optional = true }
|
||||
rusqlite = { version = "0.21.0", features = ["bundled"], optional = true }
|
||||
rustls = { version = "0.16", optional = true }
|
||||
serde = { version = "1.0.104", features = ["derive"] }
|
||||
thiserror = "1.0.9"
|
||||
time = "0.1"
|
||||
tokio = { version = "0.2.1", features = ["stream", "tcp", "udp"] }
|
||||
tokio-openssl = { version = "0.4.0", optional = true }
|
||||
|
@ -5,12 +5,9 @@
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
|
||||
#[cfg(feature = "trust-dns-resolver")]
|
||||
use failure::{Compat, Fail};
|
||||
use thiserror::Error;
|
||||
|
||||
use trust_dns_client::op::ResponseCode;
|
||||
#[cfg(feature = "trust-dns-resolver")]
|
||||
@ -18,16 +15,20 @@ use trust_dns_resolver::error::ResolveError;
|
||||
|
||||
// TODO: should this implement Failure?
|
||||
/// A query could not be fulfilled
|
||||
#[derive(Debug, EnumAsInner)]
|
||||
#[derive(Debug, EnumAsInner, Error)]
|
||||
pub enum LookupError {
|
||||
/// A record at the same Name as the query exists, but not of the queried RecordType
|
||||
#[error("The name exists, but not for the record requested")]
|
||||
NameExists,
|
||||
/// There was an error performing the lookup
|
||||
#[error("Error performing lookup: {0}")]
|
||||
ResponseCode(ResponseCode),
|
||||
/// Resolve Error
|
||||
#[cfg(feature = "trust-dns-resolver")]
|
||||
ResolveError(Compat<ResolveError>),
|
||||
#[error("Resolution error: {0}")]
|
||||
ResolveError(#[from] ResolveError),
|
||||
/// An underlying IO error occurred
|
||||
#[error("io error: {0}")]
|
||||
Io(io::Error),
|
||||
}
|
||||
|
||||
@ -62,40 +63,6 @@ impl LookupError {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for LookupError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
LookupError::NameExists => write!(f, "NameExists"),
|
||||
LookupError::ResponseCode(rc) => write!(f, "response_code: {}", rc),
|
||||
#[cfg(feature = "trust-dns-resolver")]
|
||||
LookupError::ResolveError(e) => write!(f, "resolve_error: {}", e),
|
||||
LookupError::Io(e) => write!(f, "io: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for LookupError {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
LookupError::NameExists => "record type not found at name, but others exist",
|
||||
LookupError::ResponseCode(_rc) => "an response code other than NoError returned",
|
||||
#[cfg(feature = "trust-dns-resolver")]
|
||||
LookupError::ResolveError(_e) => "the resolver encountered an error",
|
||||
LookupError::Io(_e) => "there was an underlying IO error during search",
|
||||
}
|
||||
}
|
||||
|
||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||
match self {
|
||||
LookupError::NameExists => None,
|
||||
LookupError::ResponseCode(_rc) => None,
|
||||
#[cfg(feature = "trust-dns-resolver")]
|
||||
LookupError::ResolveError(e) => e.source(),
|
||||
LookupError::Io(e) => e.source(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ResponseCode> for LookupError {
|
||||
fn from(code: ResponseCode) -> Self {
|
||||
// this should never be a NoError
|
||||
@ -104,13 +71,6 @@ impl From<ResponseCode> for LookupError {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "trust-dns-resolver")]
|
||||
impl From<ResolveError> for LookupError {
|
||||
fn from(e: ResolveError) -> Self {
|
||||
LookupError::ResolveError(e.compat())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for LookupError {
|
||||
fn from(e: io::Error) -> Self {
|
||||
LookupError::Io(e)
|
||||
|
@ -1,80 +1,74 @@
|
||||
// Copyright 2015-2018 Benjamin Fry <benjaminfry@me.com>
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use std::{fmt, io};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::proto::{trace, ExtBacktrace};
|
||||
|
||||
/// An alias for results returned by functions of this crate
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
/// The error kind for errors that get returned in the crate
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ErrorKind {
|
||||
// foreign
|
||||
/// An error got returned from IO
|
||||
#[fail(display = "io error")]
|
||||
Io,
|
||||
#[error("io error: {0}")]
|
||||
Io(#[from] io::Error),
|
||||
|
||||
/// An error occurred while decoding toml data
|
||||
#[fail(display = "toml decode error")]
|
||||
TomlDecode,
|
||||
#[error("toml decode error: {0}")]
|
||||
TomlDecode(#[from] toml::de::Error),
|
||||
}
|
||||
|
||||
/// The error type for errors that get returned in the crate
|
||||
#[derive(Debug)]
|
||||
pub struct Error {
|
||||
inner: Context<ErrorKind>,
|
||||
kind: ErrorKind,
|
||||
backtrack: Option<ExtBacktrace>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Get the kind of the error
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
self.inner.get_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl Fail for Error {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
if let Some(ref backtrace) = self.backtrack {
|
||||
fmt::Display::fmt(&self.kind, f)?;
|
||||
fmt::Debug::fmt(backtrace, f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self.kind, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(kind: ErrorKind) -> Error {
|
||||
Error {
|
||||
inner: Context::new(kind),
|
||||
kind,
|
||||
backtrack: trace!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ErrorKind>> for Error {
|
||||
fn from(inner: Context<ErrorKind>) -> Error {
|
||||
Error { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(e: io::Error) -> Error {
|
||||
e.context(ErrorKind::Io).into()
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<::toml::de::Error> for Error {
|
||||
fn from(e: ::toml::de::Error) -> Error {
|
||||
e.context(ErrorKind::TomlDecode).into()
|
||||
impl From<toml::de::Error> for Error {
|
||||
fn from(e: toml::de::Error) -> Error {
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,29 @@
|
||||
// Copyright 2015-2016 Benjamin Fry
|
||||
// Copyright 2015-2020 Benjamin Fry <benjaminfry@me.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
||||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
||||
// copied, modified, or distributed except according to those terms.
|
||||
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use std::fmt;
|
||||
|
||||
use proto::error::*;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::proto::{trace, ExtBacktrace};
|
||||
|
||||
/// An alias for results returned by functions of this crate
|
||||
pub type Result<T> = ::std::result::Result<T, Error>;
|
||||
|
||||
/// The error kind for errors that get returned in the crate
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ErrorKind {
|
||||
/// An error that occurred when recovering from journal
|
||||
#[fail(display = "error recovering from journal: {}", _0)]
|
||||
#[error("error recovering from journal: {}", _0)]
|
||||
Recovery(&'static str),
|
||||
|
||||
/// The number of inserted records didn't match the expected amount
|
||||
#[fail(display = "wrong insert count: {} expect: {}", got, expect)]
|
||||
#[error("wrong insert count: {} expect: {}", got, expect)]
|
||||
WrongInsertCount {
|
||||
/// The number of inserted records
|
||||
got: usize,
|
||||
@ -31,67 +33,58 @@ pub enum ErrorKind {
|
||||
|
||||
// foreign
|
||||
/// An error got returned by the trust-dns-proto crate
|
||||
#[fail(display = "proto error")]
|
||||
Proto,
|
||||
#[error("proto error: {0}")]
|
||||
Proto(#[from] ProtoError),
|
||||
|
||||
/// An error got returned from the rusqlite crate
|
||||
#[cfg(feature = "sqlite")]
|
||||
#[fail(display = "sqlite error")]
|
||||
Sqlite,
|
||||
#[error("sqlite error: {0}")]
|
||||
Sqlite(#[from] rusqlite::Error),
|
||||
|
||||
/// A request timed out
|
||||
#[fail(display = "request timed out")]
|
||||
#[error("request timed out")]
|
||||
Timeout,
|
||||
}
|
||||
|
||||
/// The error type for errors that get returned in the crate
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
pub struct Error {
|
||||
inner: Context<ErrorKind>,
|
||||
kind: ErrorKind,
|
||||
backtrack: Option<ExtBacktrace>,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Get the kind of the error
|
||||
pub fn kind(&self) -> &ErrorKind {
|
||||
self.inner.get_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl Fail for Error {
|
||||
fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
|
||||
fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
&self.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.inner, f)
|
||||
if let Some(ref backtrace) = self.backtrack {
|
||||
fmt::Display::fmt(&self.kind, f)?;
|
||||
fmt::Debug::fmt(backtrace, f)
|
||||
} else {
|
||||
fmt::Display::fmt(&self.kind, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(kind: ErrorKind) -> Error {
|
||||
Error {
|
||||
inner: Context::new(kind),
|
||||
kind,
|
||||
backtrack: trace!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ErrorKind>> for Error {
|
||||
fn from(inner: Context<ErrorKind>) -> Error {
|
||||
Error { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProtoError> for Error {
|
||||
fn from(e: ProtoError) -> Error {
|
||||
match *e.kind() {
|
||||
ProtoErrorKind::Timeout => e.context(ErrorKind::Timeout).into(),
|
||||
_ => e.context(ErrorKind::Proto).into(),
|
||||
ProtoErrorKind::Timeout => ErrorKind::Timeout.into(),
|
||||
_ => ErrorKind::from(e).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,6 +92,6 @@ impl From<ProtoError> for Error {
|
||||
#[cfg(feature = "sqlite")]
|
||||
impl From<rusqlite::Error> for Error {
|
||||
fn from(e: rusqlite::Error) -> Error {
|
||||
e.context(ErrorKind::Sqlite).into()
|
||||
ErrorKind::from(e).into()
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ extern crate chrono;
|
||||
#[macro_use]
|
||||
extern crate enum_as_inner;
|
||||
extern crate env_logger;
|
||||
extern crate failure;
|
||||
extern crate futures;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
@ -885,7 +885,10 @@ where
|
||||
.unwrap_err();
|
||||
|
||||
println!("got error: {:?}", err);
|
||||
assert_eq!(err.kind(), &ClientErrorKind::Timeout);
|
||||
if let ClientErrorKind::Timeout = err.kind() {
|
||||
} else {
|
||||
panic!("expected timeout error");
|
||||
}
|
||||
|
||||
io_loop
|
||||
.block_on(client.query(name, DNSClass::IN, RecordType::AAAA))
|
||||
|
@ -195,7 +195,10 @@ where
|
||||
|
||||
let err = response.unwrap_err();
|
||||
|
||||
assert_eq!(err.kind(), &ClientErrorKind::Timeout);
|
||||
if let ClientErrorKind::Timeout = err.kind() {
|
||||
} else {
|
||||
panic!("expected timeout error")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user