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