refactor: replace failure

- failure is deprecated
- thiserror for deriving Error impl
- anyhow for highlevel error handling
This commit is contained in:
Friedel Ziegelmayer
2020-04-10 22:39:28 +02:00
committed by GitHub
parent d31265895d
commit 24f4cbbb27
38 changed files with 250 additions and 656 deletions

85
Cargo.lock generated
View File

@@ -50,6 +50,11 @@ dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "anyhow"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "arrayref" name = "arrayref"
version = "0.3.6" version = "0.3.6"
@@ -101,7 +106,7 @@ dependencies = [
"pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rental 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "rental 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"stop-token 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "stop-token 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@@ -111,7 +116,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"async-std 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "async-std 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@@ -626,6 +631,7 @@ dependencies = [
name = "deltachat" name = "deltachat"
version = "1.28.0" version = "1.28.0"
dependencies = [ dependencies = [
"anyhow 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
"async-imap 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "async-imap 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"async-native-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "async-native-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"async-smtp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "async-smtp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -641,11 +647,9 @@ dependencies = [
"email 0.0.21 (git+https://github.com/deltachat/rust-email)", "email 0.0.21 (git+https://github.com/deltachat/rust-email)",
"encoded-words 0.1.0 (git+https://github.com/async-email/encoded-words)", "encoded-words 0.1.0 (git+https://github.com/async-email/encoded-words)",
"escaper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "escaper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.22.5 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.22.5 (registry+https://github.com/rust-lang/crates.io-index)",
"image-meta 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "image-meta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.2 (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)",
@@ -677,6 +681,7 @@ dependencies = [
"strum 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "strum 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"strum_macros 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "strum_macros 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
"thread-local-object 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "thread-local-object 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@@ -692,12 +697,13 @@ dependencies = [
name = "deltachat_ffi" name = "deltachat_ffi"
version = "1.28.0" version = "1.28.0"
dependencies = [ dependencies = [
"anyhow 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
"deltachat 1.28.0", "deltachat 1.28.0",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "human-panic 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@@ -808,7 +814,7 @@ dependencies = [
"hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.4.2 (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)",
"regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@@ -1194,18 +1200,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "human-panic" name = "human-panic"
version = "1.0.1" version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"backtrace 0.3.44 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace 0.3.44 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"os_type 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "os_type 2.2.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)",
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@@ -1282,12 +1286,12 @@ dependencies = [
[[package]] [[package]]
name = "image-meta" name = "image-meta"
version = "0.1.0" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"skeptic 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)", "skeptic 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@@ -1852,7 +1856,7 @@ dependencies = [
"sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
"try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"x25519-dalek 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "x25519-dalek 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2686,14 +2690,6 @@ dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "termcolor"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.0" version = "1.1.0"
@@ -2704,15 +2700,15 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.11" version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"thiserror-impl 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", "thiserror-impl 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.11" version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2786,7 +2782,7 @@ dependencies = [
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.4.10" version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ 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)",
@@ -2897,15 +2893,6 @@ name = "utf8parse"
version = "0.1.1" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "uuid"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "0.8.1" version = "0.8.1"
@@ -3074,14 +3061,6 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wincolor"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "winreg" name = "winreg"
version = "0.6.2" version = "0.6.2"
@@ -3143,6 +3122,7 @@ dependencies = [
"checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100"
"checksum aho-corasick 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d5e63fd144e18ba274ae7095c0197a870a7b9468abc801dd62f190d80817d2ec" "checksum aho-corasick 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d5e63fd144e18ba274ae7095c0197a870a7b9468abc801dd62f190d80817d2ec"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum anyhow 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "d9a60d744a80c30fcb657dfe2c1b22bcb3e814c1a1e3674f32bf5820b570fbff"
"checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" "checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
"checksum arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" "checksum arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9"
"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" "checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
@@ -3268,14 +3248,14 @@ dependencies = [
"checksum http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b708cc7f06493459026f53b9a61a7a121a5d1ec6238dee58ea4941132b30156b" "checksum http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b708cc7f06493459026f53b9a61a7a121a5d1ec6238dee58ea4941132b30156b"
"checksum http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" "checksum http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b"
"checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
"checksum human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "21638c5955a6daf3ecc42cae702335fc37a72a4abcc6959ce457b31a7d43bbdd" "checksum human-panic 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "39f357a500abcbd7c5f967c1d45c8838585b36743823b9d43488f24850534e36"
"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" "checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
"checksum hyper 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e7b15203263d1faa615f9337d79c1d37959439dc46c2b4faab33286fadc2a1c5" "checksum hyper 0.13.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e7b15203263d1faa615f9337d79c1d37959439dc46c2b4faab33286fadc2a1c5"
"checksum hyper-tls 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa" "checksum hyper-tls 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa"
"checksum ident_case 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" "checksum ident_case 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
"checksum image 0.22.5 (registry+https://github.com/rust-lang/crates.io-index)" = "08ed2ada878397b045454ac7cfb011d73132c59f31a955d230bd1f1c2e68eb4a" "checksum image 0.22.5 (registry+https://github.com/rust-lang/crates.io-index)" = "08ed2ada878397b045454ac7cfb011d73132c59f31a955d230bd1f1c2e68eb4a"
"checksum image-meta 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b00861cbbb254a627d8acc0cec786b484297d896ab8f20fdc8e28536a3e918ef" "checksum image-meta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a2da7b4225d0954c9b8ba1a0dcec85be29f496cba4d85f9390426f810e3ab0d"
"checksum imap-proto 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "16a6def1d5ac8975d70b3fd101d57953fe3278ef2ee5d7816cba54b1d1dfc22f" "checksum imap-proto 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "16a6def1d5ac8975d70b3fd101d57953fe3278ef2ee5d7816cba54b1d1dfc22f"
"checksum indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" "checksum indexmap 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292"
"checksum inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" "checksum inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff"
@@ -3428,17 +3408,16 @@ dependencies = [
"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"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 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83"
"checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" "checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
"checksum thiserror 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ee14bf8e6767ab4c687c9e8bc003879e042a96fd67a3ba5934eadb6536bef4db" "checksum thiserror 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "f0570dc61221295909abdb95c739f2e74325e14293b2026b0a7e195091ec54ae"
"checksum thiserror-impl 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "a7b51e1fbc44b5a0840be594fbc0f960be09050f2617e61e6aa43bef97cd3ef4" "checksum thiserror-impl 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "227362df41d566be41a28f64401e07a043157c21c14b9785a0d8e256f940a8fd"
"checksum thread-local-object 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7da3caa820d0308c84c8654f6cafd81cc3195d45433311cbe22fcf44fc8be071" "checksum thread-local-object 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7da3caa820d0308c84c8654f6cafd81cc3195d45433311cbe22fcf44fc8be071"
"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.13 (registry+https://github.com/rust-lang/crates.io-index)" = "0fa5e81d6bc4e67fe889d5783bd2a128ab2e0cfa487e0be16b6a8d177b101616" "checksum tokio 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "0fa5e81d6bc4e67fe889d5783bd2a128ab2e0cfa487e0be16b6a8d177b101616"
"checksum tokio-tls 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bde02a3a5291395f59b06ec6945a3077602fac2b07eeeaf0dee2122f3619828" "checksum tokio-tls 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bde02a3a5291395f59b06ec6945a3077602fac2b07eeeaf0dee2122f3619828"
"checksum tokio-util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "571da51182ec208780505a32528fc5512a8fe1443ab960b3f2f3ef093cd16930" "checksum tokio-util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "571da51182ec208780505a32528fc5512a8fe1443ab960b3f2f3ef093cd16930"
"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" "checksum toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
"checksum tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" "checksum tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860"
"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
@@ -3455,7 +3434,6 @@ dependencies = [
"checksum unsafe-any 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" "checksum unsafe-any 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f"
"checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" "checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
"checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d" "checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d"
"checksum uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e1436e58182935dcd9ce0add9ea0b558e8a87befe01c1a301e6020aeb0876363"
"checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" "checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11"
"checksum vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" "checksum vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168"
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
@@ -3478,7 +3456,6 @@ dependencies = [
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80" "checksum winapi-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfbf554c6ad11084fb7517daca16cfdcaccbdadba4fc336f032a8b12c2ad80"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767"
"checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" "checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9"
"checksum winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7daf138b6b14196e3830a588acf1e86966c694d3e8fb026fb105b8b5dca07e6e" "checksum winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7daf138b6b14196e3830a588acf1e86966c694d3e8fb026fb105b8b5dca07e6e"
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"

View File

@@ -32,8 +32,6 @@ percent-encoding = "2.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
chrono = "0.4.6" chrono = "0.4.6"
failure = "0.1.5"
failure_derive = "0.1.5"
indexmap = "1.3.0" indexmap = "1.3.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"
regex = "1.1.6" regex = "1.1.6"
@@ -60,6 +58,8 @@ image = { version = "0.22.4", default-features=false, features = ["gif_codec", "
pretty_env_logger = "0.3.1" pretty_env_logger = "0.3.1"
rustyline = { version = "4.1.0", optional = true } rustyline = { version = "4.1.0", optional = true }
thiserror = "1.0.14"
anyhow = "1.0.28"
[dev-dependencies] [dev-dependencies]
tempfile = "3.0" tempfile = "3.0"

View File

@@ -19,8 +19,9 @@ deltachat = { path = "../", default-features = false }
libc = "0.2" libc = "0.2"
human-panic = "1.0.1" human-panic = "1.0.1"
num-traits = "0.2.6" num-traits = "0.2.6"
failure = "0.1.6"
serde_json = "1.0" serde_json = "1.0"
anyhow = "1.0.28"
thiserror = "1.0.14"
[features] [features]
default = ["vendored", "nightly"] default = ["vendored", "nightly"]

View File

@@ -120,17 +120,17 @@ impl ContextWrapper {
/// Unlock the context and execute a closure with it. /// Unlock the context and execute a closure with it.
/// ///
/// This is like [ContextWrapper::with_inner] but uses /// This is like [ContextWrapper::with_inner] but uses
/// [failure::Error] as error type. This allows you to write a /// [anyhow::Error] as error type. This allows you to write a
/// closure which could produce many errors, use the `?` operator /// closure which could produce many errors, use the `?` operator
/// to return them and handle them all as the return of this call. /// to return them and handle them all as the return of this call.
fn try_inner<T, F>(&self, ctxfn: F) -> Result<T, failure::Error> fn try_inner<T, F>(&self, ctxfn: F) -> Result<T, anyhow::Error>
where where
F: FnOnce(&Context) -> Result<T, failure::Error>, F: FnOnce(&Context) -> Result<T, anyhow::Error>,
{ {
let guard = self.inner.read().unwrap(); let guard = self.inner.read().unwrap();
match guard.as_ref() { match guard.as_ref() {
Some(ref ctx) => ctxfn(ctx), Some(ref ctx) => ctxfn(ctx),
None => Err(failure::err_msg("context not open")), None => Err(anyhow::format_err!("context not open")),
} }
} }

View File

@@ -1,4 +1,3 @@
use failure::Fail;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::ptr; use std::ptr;
@@ -31,13 +30,13 @@ unsafe fn dc_strdup(s: *const libc::c_char) -> *mut libc::c_char {
} }
/// Error type for the [OsStrExt] trait /// Error type for the [OsStrExt] trait
#[derive(Debug, Fail, PartialEq)] #[derive(Debug, PartialEq, thiserror::Error)]
pub(crate) enum CStringError { pub(crate) enum CStringError {
/// The string contains an interior null byte /// The string contains an interior null byte
#[fail(display = "String contains an interior null byte")] #[error("String contains an interior null byte")]
InteriorNullByte, InteriorNullByte,
/// The string is not valid Unicode /// The string is not valid Unicode
#[fail(display = "String is not valid unicode")] #[error("String is not valid unicode")]
NotUnicode, NotUnicode,
} }

View File

@@ -1,6 +1,7 @@
use std::path::Path; use std::path::Path;
use std::str::FromStr; use std::str::FromStr;
use anyhow::{bail, ensure};
use deltachat::chat::{self, Chat, ChatId, ChatVisibility}; use deltachat::chat::{self, Chat, ChatId, ChatVisibility};
use deltachat::chatlist::*; use deltachat::chatlist::*;
use deltachat::constants::*; use deltachat::constants::*;
@@ -91,7 +92,7 @@ fn dc_reset_tables(context: &Context, bits: i32) -> i32 {
1 1
} }
fn dc_poke_eml_file(context: &Context, filename: impl AsRef<Path>) -> Result<(), Error> { fn dc_poke_eml_file(context: &Context, filename: impl AsRef<Path>) -> Result<(), anyhow::Error> {
let data = dc_read_file(context, filename)?; let data = dc_read_file(context, filename)?;
if let Err(err) = dc_receive_imf(context, &data, "import", 0, false) { if let Err(err) = dc_receive_imf(context, &data, "import", 0, false) {
@@ -297,7 +298,7 @@ fn chat_prefix(chat: &Chat) -> &'static str {
chat.typ.into() chat.typ.into()
} }
pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> { pub fn dc_cmdline(context: &Context, line: &str) -> Result<(), Error> {
let chat_id = *context.cmdline_sel_chat_id.read().unwrap(); let chat_id = *context.cmdline_sel_chat_id.read().unwrap();
let mut sel_chat = if !chat_id.is_unset() { let mut sel_chat = if !chat_id.is_unset() {
Chat::load_from_db(context, chat_id).ok() Chat::load_from_db(context, chat_id).ok()

View File

@@ -7,8 +7,6 @@
#[macro_use] #[macro_use]
extern crate deltachat; extern crate deltachat;
#[macro_use] #[macro_use]
extern crate failure;
#[macro_use]
extern crate lazy_static; extern crate lazy_static;
#[macro_use] #[macro_use]
extern crate rusqlite; extern crate rusqlite;
@@ -20,6 +18,7 @@ use std::process::Command;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex, RwLock}; use std::sync::{Arc, Mutex, RwLock};
use anyhow::{bail, Error};
use deltachat::chat::ChatId; use deltachat::chat::ChatId;
use deltachat::config; use deltachat::config;
use deltachat::context::*; use deltachat::context::*;
@@ -370,10 +369,10 @@ impl Highlighter for DcHelper {
impl Helper for DcHelper {} impl Helper for DcHelper {}
fn main_0(args: Vec<String>) -> Result<(), failure::Error> { fn main_0(args: Vec<String>) -> Result<(), Error> {
if args.len() < 2 { if args.len() < 2 {
println!("Error: Bad arguments, expected [db-name]."); println!("Error: Bad arguments, expected [db-name].");
return Err(format_err!("No db-name specified")); bail!("No db-name specified");
} }
let context = Context::new( let context = Context::new(
Box::new(receive_event), Box::new(receive_event),
@@ -443,7 +442,7 @@ enum ExitResult {
Exit, Exit,
} }
fn handle_cmd(line: &str, ctx: Arc<RwLock<Context>>) -> Result<ExitResult, failure::Error> { fn handle_cmd(line: &str, ctx: Arc<RwLock<Context>>) -> Result<ExitResult, Error> {
let mut args = line.splitn(2, ' '); let mut args = line.splitn(2, ' ');
let arg0 = args.next().unwrap_or_default(); let arg0 = args.next().unwrap_or_default();
let arg1 = args.next().unwrap_or_default(); let arg1 = args.next().unwrap_or_default();
@@ -526,7 +525,7 @@ fn handle_cmd(line: &str, ctx: Arc<RwLock<Context>>) -> Result<ExitResult, failu
Ok(ExitResult::Continue) Ok(ExitResult::Continue)
} }
pub fn main() -> Result<(), failure::Error> { pub fn main() -> Result<(), Error> {
let _ = pretty_env_logger::try_init(); let _ = pretty_env_logger::try_init();
let args: Vec<String> = std::env::args().collect(); let args: Vec<String> = std::env::args().collect();

View File

@@ -6,13 +6,13 @@ use std::fs;
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use self::image::GenericImageView; use image::GenericImageView;
use thiserror::Error;
use crate::constants::AVATAR_SIZE; use crate::constants::AVATAR_SIZE;
use crate::context::Context; use crate::context::Context;
use crate::events::Event; use crate::events::Event;
extern crate image;
/// Represents a file in the blob directory. /// Represents a file in the blob directory.
/// ///
/// The object has a name, which will always be valid UTF-8. Having a /// The object has a name, which will always be valid UTF-8. Having a
@@ -56,7 +56,6 @@ impl<'a> BlobObject<'a> {
blobdir: blobdir.to_path_buf(), blobdir: blobdir.to_path_buf(),
blobname: name.clone(), blobname: name.clone(),
cause: err, cause: err,
backtrace: failure::Backtrace::new(),
})?; })?;
let blob = BlobObject { let blob = BlobObject {
blobdir, blobdir,
@@ -84,7 +83,6 @@ impl<'a> BlobObject<'a> {
blobdir: dir.to_path_buf(), blobdir: dir.to_path_buf(),
blobname: name, blobname: name,
cause: err, cause: err,
backtrace: failure::Backtrace::new(),
}); });
} else { } else {
name = format!("{}-{}{}", stem, rand::random::<u32>(), ext); name = format!("{}-{}{}", stem, rand::random::<u32>(), ext);
@@ -97,7 +95,6 @@ impl<'a> BlobObject<'a> {
blobdir: dir.to_path_buf(), blobdir: dir.to_path_buf(),
blobname: name, blobname: name,
cause: std::io::Error::new(std::io::ErrorKind::Other, "supposedly unreachable"), cause: std::io::Error::new(std::io::ErrorKind::Other, "supposedly unreachable"),
backtrace: failure::Backtrace::new(),
}) })
} }
@@ -122,7 +119,6 @@ impl<'a> BlobObject<'a> {
blobname: String::from(""), blobname: String::from(""),
src: src.as_ref().to_path_buf(), src: src.as_ref().to_path_buf(),
cause: err, cause: err,
backtrace: failure::Backtrace::new(),
})?; })?;
let (stem, ext) = BlobObject::sanitise_name(&src.as_ref().to_string_lossy()); let (stem, ext) = BlobObject::sanitise_name(&src.as_ref().to_string_lossy());
let (name, mut dst_file) = BlobObject::create_new_file(context.get_blobdir(), &stem, &ext)?; let (name, mut dst_file) = BlobObject::create_new_file(context.get_blobdir(), &stem, &ext)?;
@@ -138,7 +134,6 @@ impl<'a> BlobObject<'a> {
blobname: name_for_err, blobname: name_for_err,
src: src.as_ref().to_path_buf(), src: src.as_ref().to_path_buf(),
cause: err, cause: err,
backtrace: failure::Backtrace::new(),
} }
})?; })?;
let blob = BlobObject { let blob = BlobObject {
@@ -198,17 +193,14 @@ impl<'a> BlobObject<'a> {
.map_err(|_| BlobError::WrongBlobdir { .map_err(|_| BlobError::WrongBlobdir {
blobdir: context.get_blobdir().to_path_buf(), blobdir: context.get_blobdir().to_path_buf(),
src: path.as_ref().to_path_buf(), src: path.as_ref().to_path_buf(),
backtrace: failure::Backtrace::new(),
})?; })?;
if !BlobObject::is_acceptible_blob_name(&rel_path) { if !BlobObject::is_acceptible_blob_name(&rel_path) {
return Err(BlobError::WrongName { return Err(BlobError::WrongName {
blobname: path.as_ref().to_path_buf(), blobname: path.as_ref().to_path_buf(),
backtrace: failure::Backtrace::new(),
}); });
} }
let name = rel_path.to_str().ok_or_else(|| BlobError::WrongName { let name = rel_path.to_str().ok_or_else(|| BlobError::WrongName {
blobname: path.as_ref().to_path_buf(), blobname: path.as_ref().to_path_buf(),
backtrace: failure::Backtrace::new(),
})?; })?;
BlobObject::from_name(context, name.to_string()) BlobObject::from_name(context, name.to_string())
} }
@@ -236,7 +228,6 @@ impl<'a> BlobObject<'a> {
if !BlobObject::is_acceptible_blob_name(&name) { if !BlobObject::is_acceptible_blob_name(&name) {
return Err(BlobError::WrongName { return Err(BlobError::WrongName {
blobname: PathBuf::from(name), blobname: PathBuf::from(name),
backtrace: failure::Backtrace::new(),
}); });
} }
Ok(BlobObject { Ok(BlobObject {
@@ -359,7 +350,6 @@ impl<'a> BlobObject<'a> {
blobdir: context.get_blobdir().to_path_buf(), blobdir: context.get_blobdir().to_path_buf(),
blobname: blob_abs.to_str().unwrap_or_default().to_string(), blobname: blob_abs.to_str().unwrap_or_default().to_string(),
cause: err, cause: err,
backtrace: failure::Backtrace::new(),
})?; })?;
if img.width() <= AVATAR_SIZE && img.height() <= AVATAR_SIZE { if img.width() <= AVATAR_SIZE && img.height() <= AVATAR_SIZE {
@@ -372,7 +362,6 @@ impl<'a> BlobObject<'a> {
blobdir: context.get_blobdir().to_path_buf(), blobdir: context.get_blobdir().to_path_buf(),
blobname: blob_abs.to_str().unwrap_or_default().to_string(), blobname: blob_abs.to_str().unwrap_or_default().to_string(),
cause: err, cause: err,
backtrace: failure::Backtrace::new(),
})?; })?;
Ok(()) Ok(())
@@ -386,98 +375,41 @@ impl<'a> fmt::Display for BlobObject<'a> {
} }
/// Errors for the [BlobObject]. /// Errors for the [BlobObject].
#[derive(Fail, Debug)] #[derive(Debug, Error)]
pub enum BlobError { pub enum BlobError {
#[error("Failed to create blob {blobname} in {}", .blobdir.display())]
CreateFailure { CreateFailure {
blobdir: PathBuf, blobdir: PathBuf,
blobname: String, blobname: String,
#[cause] #[source]
cause: std::io::Error, cause: std::io::Error,
backtrace: failure::Backtrace,
}, },
#[error("Failed to write data to blob {blobname} in {}", .blobdir.display())]
WriteFailure { WriteFailure {
blobdir: PathBuf, blobdir: PathBuf,
blobname: String, blobname: String,
#[cause] #[source]
cause: std::io::Error, cause: std::io::Error,
backtrace: failure::Backtrace,
}, },
#[error("Failed to copy data from {} to blob {blobname} in {}", .src.display(), .blobdir.display())]
CopyFailure { CopyFailure {
blobdir: PathBuf, blobdir: PathBuf,
blobname: String, blobname: String,
src: PathBuf, src: PathBuf,
#[cause] #[source]
cause: std::io::Error, cause: std::io::Error,
backtrace: failure::Backtrace,
}, },
#[error("Failed to recode to blob {blobname} in {}", .blobdir.display())]
RecodeFailure { RecodeFailure {
blobdir: PathBuf, blobdir: PathBuf,
blobname: String, blobname: String,
#[cause] #[source]
cause: image::ImageError, cause: image::ImageError,
backtrace: failure::Backtrace,
}, },
WrongBlobdir { #[error("File path {} is not in {}", .src.display(), .blobdir.display())]
blobdir: PathBuf, WrongBlobdir { blobdir: PathBuf, src: PathBuf },
src: PathBuf, #[error("Blob has a badname {}", .blobname.display())]
backtrace: failure::Backtrace, WrongName { blobname: PathBuf },
},
WrongName {
blobname: PathBuf,
backtrace: failure::Backtrace,
},
}
// Implementing Display is done by hand because the failure
// #[fail(display = "...")] syntax does not allow using
// `blobdir.display()`.
impl fmt::Display for BlobError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Match on the data rather than kind, they are equivalent for
// identifying purposes but contain the actual data we need.
match &self {
BlobError::CreateFailure {
blobdir, blobname, ..
} => write!(
f,
"Failed to create blob {} in {}",
blobname,
blobdir.display()
),
BlobError::WriteFailure {
blobdir, blobname, ..
} => write!(
f,
"Failed to write data to blob {} in {}",
blobname,
blobdir.display()
),
BlobError::CopyFailure {
blobdir,
blobname,
src,
..
} => write!(
f,
"Failed to copy data from {} to blob {} in {}",
src.display(),
blobname,
blobdir.display(),
),
BlobError::RecodeFailure {
blobdir, blobname, ..
} => write!(f, "Failed to recode {} in {}", blobname, blobdir.display(),),
BlobError::WrongBlobdir { blobdir, src, .. } => write!(
f,
"File path {} is not in blobdir {}",
src.display(),
blobdir.display(),
),
BlobError::WrongName { blobname, .. } => {
write!(f, "Blob has a bad name: {}", blobname.display(),)
}
}
}
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -15,7 +15,7 @@ use crate::constants::*;
use crate::contact::*; use crate::contact::*;
use crate::context::Context; use crate::context::Context;
use crate::dc_tools::*; use crate::dc_tools::*;
use crate::error::Error; use crate::error::{bail, ensure, format_err, Error};
use crate::events::Event; use crate::events::Event;
use crate::job::*; use crate::job::*;
use crate::message::{self, InvalidMsgId, Message, MessageState, MsgId}; use crate::message::{self, InvalidMsgId, Message, MessageState, MsgId};

View File

@@ -5,7 +5,7 @@ use crate::chat::*;
use crate::constants::*; use crate::constants::*;
use crate::contact::*; use crate::contact::*;
use crate::context::*; use crate::context::*;
use crate::error::Result; use crate::error::{ensure, Result};
use crate::lot::Lot; use crate::lot::Lot;
use crate::message::{Message, MessageState, MsgId}; use crate::message::{Message, MessageState, MsgId};
use crate::stock::StockMessage; use crate::stock::StockMessage;

View File

@@ -9,33 +9,7 @@ use crate::context::Context;
use crate::login_param::LoginParam; use crate::login_param::LoginParam;
use super::read_url::read_url; use super::read_url::read_url;
use super::Error;
#[derive(Debug, Fail)]
pub enum Error {
#[fail(display = "Invalid email address: {:?}", _0)]
InvalidEmailAddress(String),
#[fail(display = "XML error at position {}", position)]
InvalidXml {
position: usize,
#[cause]
error: quick_xml::Error,
},
#[fail(display = "Bad or incomplete autoconfig")]
IncompleteAutoconfig(LoginParam),
#[fail(display = "Failed to get URL {}", _0)]
ReadUrlError(#[cause] super::read_url::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
impl From<super::read_url::Error> for Error {
fn from(err: super::read_url::Error) -> Error {
Error::ReadUrlError(err)
}
}
#[derive(Debug)] #[derive(Debug)]
struct MozAutoconfigure<'a> { struct MozAutoconfigure<'a> {
@@ -65,7 +39,7 @@ enum MozConfigTag {
Username, Username,
} }
fn parse_xml(in_emailaddr: &str, xml_raw: &str) -> Result<LoginParam> { fn parse_xml(in_emailaddr: &str, xml_raw: &str) -> Result<LoginParam, Error> {
let mut reader = quick_xml::Reader::from_str(xml_raw); let mut reader = quick_xml::Reader::from_str(xml_raw);
reader.trim_text(true); reader.trim_text(true);
@@ -125,7 +99,7 @@ pub fn moz_autoconfigure(
context: &Context, context: &Context,
url: &str, url: &str,
param_in: &LoginParam, param_in: &LoginParam,
) -> Result<LoginParam> { ) -> Result<LoginParam, Error> {
let xml_raw = read_url(context, url)?; let xml_raw = read_url(context, url)?;
let res = parse_xml(&param_in.addr, &xml_raw); let res = parse_xml(&param_in.addr, &xml_raw);

View File

@@ -8,33 +8,7 @@ use crate::context::Context;
use crate::login_param::LoginParam; use crate::login_param::LoginParam;
use super::read_url::read_url; use super::read_url::read_url;
use super::Error;
#[derive(Debug, Fail)]
pub enum Error {
#[fail(display = "XML error at position {}", position)]
InvalidXml {
position: usize,
#[cause]
error: quick_xml::Error,
},
#[fail(display = "Bad or incomplete autoconfig")]
IncompleteAutoconfig(LoginParam),
#[fail(display = "Failed to get URL {}", _0)]
ReadUrlError(#[cause] super::read_url::Error),
#[fail(display = "Number of redirection is exceeded")]
RedirectionError,
}
pub type Result<T> = std::result::Result<T, Error>;
impl From<super::read_url::Error> for Error {
fn from(err: super::read_url::Error) -> Error {
Error::ReadUrlError(err)
}
}
struct OutlookAutodiscover { struct OutlookAutodiscover {
pub out: LoginParam, pub out: LoginParam,
@@ -52,7 +26,7 @@ enum ParsingResult {
RedirectUrl(String), RedirectUrl(String),
} }
fn parse_xml(xml_raw: &str) -> Result<ParsingResult> { fn parse_xml(xml_raw: &str) -> Result<ParsingResult, Error> {
let mut outlk_ad = OutlookAutodiscover { let mut outlk_ad = OutlookAutodiscover {
out: LoginParam::new(), out: LoginParam::new(),
out_imap_set: false, out_imap_set: false,
@@ -143,7 +117,7 @@ pub fn outlk_autodiscover(
context: &Context, context: &Context,
url: &str, url: &str,
_param_in: &LoginParam, _param_in: &LoginParam,
) -> Result<LoginParam> { ) -> Result<LoginParam, Error> {
let mut url = url.to_string(); let mut url = url.to_string();
/* Follow up to 10 xml-redirects (http-redirects are followed in read_url() */ /* Follow up to 10 xml-redirects (http-redirects are followed in read_url() */
for _i in 0..10 { for _i in 0..10 {

View File

@@ -12,6 +12,7 @@ use crate::config::Config;
use crate::constants::*; use crate::constants::*;
use crate::context::Context; use crate::context::Context;
use crate::dc_tools::*; use crate::dc_tools::*;
use crate::error::format_err;
use crate::job::{self, job_add, job_kill_action}; use crate::job::{self, job_add, job_kill_action};
use crate::login_param::{CertificateChecks, LoginParam}; use crate::login_param::{CertificateChecks, LoginParam};
use crate::oauth2::*; use crate::oauth2::*;
@@ -651,6 +652,28 @@ fn try_smtp_one_param(context: &Context, param: &LoginParam) -> Option<bool> {
} }
} }
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Invalid email address: {0:?}")]
InvalidEmailAddress(String),
#[error("XML error at position {position}")]
InvalidXml {
position: usize,
#[source]
error: quick_xml::Error,
},
#[error("Bad or incomplete autoconfig")]
IncompleteAutoconfig(LoginParam),
#[error("Failed to get URL")]
ReadUrlError(#[from] self::read_url::Error),
#[error("Number of redirection is exceeded")]
RedirectionError,
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View File

@@ -1,14 +1,12 @@
use crate::context::Context; use crate::context::Context;
#[derive(Debug, Fail)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
#[fail(display = "URL request error")] #[error("URL request error")]
GetError(#[cause] reqwest::Error), GetError(#[from] reqwest::Error),
} }
pub type Result<T> = std::result::Result<T, Error>; pub fn read_url(context: &Context, url: &str) -> Result<String, Error> {
pub fn read_url(context: &Context, url: &str) -> Result<String> {
info!(context, "Requesting URL {}", url); info!(context, "Requesting URL {}", url);
match reqwest::blocking::Client::new() match reqwest::blocking::Client::new()

View File

@@ -13,7 +13,7 @@ use crate::constants::*;
use crate::context::Context; use crate::context::Context;
use crate::dc_tools::*; use crate::dc_tools::*;
use crate::e2ee; use crate::e2ee;
use crate::error::{Error, Result}; use crate::error::{bail, ensure, format_err, Result};
use crate::events::Event; use crate::events::Event;
use crate::key::*; use crate::key::*;
use crate::login_param::LoginParam; use crate::login_param::LoginParam;
@@ -1120,10 +1120,9 @@ fn cat_fingerprint(
impl Context { impl Context {
/// determine whether the specified addr maps to the/a self addr /// determine whether the specified addr maps to the/a self addr
pub fn is_self_addr(&self, addr: &str) -> Result<bool> { pub fn is_self_addr(&self, addr: &str) -> Result<bool> {
let self_addr = match self.get_config(Config::ConfiguredAddr) { let self_addr = self
Some(s) => s, .get_config(Config::ConfiguredAddr)
None => return Err(Error::NotConfigured), .ok_or_else(|| format_err!("Not configured"))?;
};
Ok(addr_cmp(self_addr, addr)) Ok(addr_cmp(self_addr, addr))
} }

View File

@@ -9,7 +9,7 @@ use crate::constants::*;
use crate::contact::*; use crate::contact::*;
use crate::context::Context; use crate::context::Context;
use crate::dc_tools::*; use crate::dc_tools::*;
use crate::error::Result; use crate::error::{bail, ensure, Result};
use crate::events::Event; use crate::events::Event;
use crate::headerdef::HeaderDef; use crate::headerdef::HeaderDef;
use crate::job::*; use crate::job::*;

View File

@@ -12,7 +12,7 @@ use chrono::{Local, TimeZone};
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use crate::context::Context; use crate::context::Context;
use crate::error::Error; use crate::error::{bail, ensure, Error};
use crate::events::Event; use crate::events::Event;
pub(crate) fn dc_exactly_one_bit_set(v: i32) -> bool { pub(crate) fn dc_exactly_one_bit_set(v: i32) -> bool {

View File

@@ -200,15 +200,13 @@ fn load_or_generate_self_public_key(
self_addr: impl AsRef<str>, self_addr: impl AsRef<str>,
) -> Result<SignedPublicKey> { ) -> Result<SignedPublicKey> {
if let Some(key) = Key::from_self_public(context, &self_addr, &context.sql) { if let Some(key) = Key::from_self_public(context, &self_addr, &context.sql) {
return SignedPublicKey::try_from(key) return SignedPublicKey::try_from(key).map_err(|_| format_err!("Not a public key"));
.map_err(|_| Error::Message("Not a public key".into()));
} }
let _guard = context.generating_key_mutex.lock().unwrap(); let _guard = context.generating_key_mutex.lock().unwrap();
// Check again in case the key was generated while we were waiting for the lock. // Check again in case the key was generated while we were waiting for the lock.
if let Some(key) = Key::from_self_public(context, &self_addr, &context.sql) { if let Some(key) = Key::from_self_public(context, &self_addr, &context.sql) {
return SignedPublicKey::try_from(key) return SignedPublicKey::try_from(key).map_err(|_| format_err!("Not a public key"));
.map_err(|_| Error::Message("Not a public key".into()));
} }
let start = std::time::Instant::now(); let start = std::time::Instant::now();

View File

@@ -1,189 +1,13 @@
//! # Error handling //! # Error handling
use lettre_email::mime; pub use anyhow::{bail, ensure, format_err, Error, Result};
#[derive(Debug, Fail)] // #[fail(display = "Invalid Message ID.")]
pub enum Error { // InvalidMsgId,
#[fail(display = "{:?}", _0)] // #[fail(display = "Watch folder not found {:?}", _0)]
Failure(failure::Error), // WatchFolderNotFound(String),
// #[fail(display = "Not Configured")]
#[fail(display = "SQL error: {:?}", _0)] // NotConfigured,
SqlError(#[cause] crate::sql::Error),
#[fail(display = "{:?}", _0)]
Io(std::io::Error),
#[fail(display = "{:?}", _0)]
Message(String),
#[fail(display = "{:?}", _0)]
MessageWithCause(String, #[cause] failure::Error, failure::Backtrace),
#[fail(display = "{:?}", _0)]
Image(image_meta::ImageError),
#[fail(display = "{:?}", _0)]
Utf8(std::str::Utf8Error),
#[fail(display = "PGP: {:?}", _0)]
Pgp(pgp::errors::Error),
#[fail(display = "Base64Decode: {:?}", _0)]
Base64Decode(base64::DecodeError),
#[fail(display = "{:?}", _0)]
FromUtf8(std::string::FromUtf8Error),
#[fail(display = "{}", _0)]
BlobError(#[cause] crate::blob::BlobError),
#[fail(display = "Invalid Message ID.")]
InvalidMsgId,
#[fail(display = "Watch folder not found {:?}", _0)]
WatchFolderNotFound(String),
#[fail(display = "Invalid Email: {:?}", _0)]
MailParseError(#[cause] mailparse::MailParseError),
#[fail(display = "Building invalid Email: {:?}", _0)]
LettreError(#[cause] lettre_email::error::Error),
#[fail(display = "SMTP error: {:?}", _0)]
SmtpError(#[cause] async_smtp::error::Error),
#[fail(display = "FromStr error: {:?}", _0)]
FromStr(#[cause] mime::FromStrError),
#[fail(display = "Not Configured")]
NotConfigured,
}
pub type Result<T> = std::result::Result<T, Error>;
impl From<crate::sql::Error> for Error {
fn from(err: crate::sql::Error) -> Error {
Error::SqlError(err)
}
}
impl From<base64::DecodeError> for Error {
fn from(err: base64::DecodeError) -> Error {
Error::Base64Decode(err)
}
}
impl From<failure::Error> for Error {
fn from(err: failure::Error) -> Error {
Error::Failure(err)
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Error {
Error::Io(err)
}
}
impl From<std::str::Utf8Error> for Error {
fn from(err: std::str::Utf8Error) -> Error {
Error::Utf8(err)
}
}
impl From<image_meta::ImageError> for Error {
fn from(err: image_meta::ImageError) -> Error {
Error::Image(err)
}
}
impl From<pgp::errors::Error> for Error {
fn from(err: pgp::errors::Error) -> Error {
Error::Pgp(err)
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(err: std::string::FromUtf8Error) -> Error {
Error::FromUtf8(err)
}
}
impl From<crate::blob::BlobError> for Error {
fn from(err: crate::blob::BlobError) -> Error {
Error::BlobError(err)
}
}
impl From<crate::message::InvalidMsgId> for Error {
fn from(_err: crate::message::InvalidMsgId) -> Error {
Error::InvalidMsgId
}
}
impl From<crate::key::SaveKeyError> for Error {
fn from(err: crate::key::SaveKeyError) -> Error {
Error::MessageWithCause(format!("{}", err), err.into(), failure::Backtrace::new())
}
}
impl From<crate::pgp::PgpKeygenError> for Error {
fn from(err: crate::pgp::PgpKeygenError) -> Error {
Error::MessageWithCause(format!("{}", err), err.into(), failure::Backtrace::new())
}
}
impl From<mailparse::MailParseError> for Error {
fn from(err: mailparse::MailParseError) -> Error {
Error::MailParseError(err)
}
}
impl From<lettre_email::error::Error> for Error {
fn from(err: lettre_email::error::Error) -> Error {
Error::LettreError(err)
}
}
impl From<mime::FromStrError> for Error {
fn from(err: mime::FromStrError) -> Error {
Error::FromStr(err)
}
}
#[macro_export]
macro_rules! bail {
($e:expr) => {
return Err($crate::error::Error::Message($e.to_string()));
};
($fmt:expr, $($arg:tt)+) => {
return Err($crate::error::Error::Message(format!($fmt, $($arg)+)));
};
}
#[macro_export]
macro_rules! format_err {
($e:expr) => {
$crate::error::Error::Message($e.to_string());
};
($fmt:expr, $($arg:tt)+) => {
$crate::error::Error::Message(format!($fmt, $($arg)+));
};
}
#[macro_export(local_inner_macros)]
macro_rules! ensure {
($cond:expr, $e:expr) => {
if !($cond) {
bail!($e);
}
};
($cond:expr, $fmt:expr, $($arg:tt)+) => {
if !($cond) {
bail!($fmt, $($arg)+);
}
};
}
#[macro_export] #[macro_export]
macro_rules! ensure_eq { macro_rules! ensure_eq {

View File

@@ -15,28 +15,22 @@ use super::session::Session;
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Fail)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
#[fail(display = "IMAP IDLE protocol failed to init/complete")] #[error("IMAP IDLE protocol failed to init/complete")]
IdleProtocolFailed(#[cause] async_imap::error::Error), IdleProtocolFailed(#[from] async_imap::error::Error),
#[fail(display = "IMAP IDLE protocol timed out")] #[error("IMAP IDLE protocol timed out")]
IdleTimeout(#[cause] async_std::future::TimeoutError), IdleTimeout(#[from] async_std::future::TimeoutError),
#[fail(display = "IMAP server does not have IDLE capability")] #[error("IMAP server does not have IDLE capability")]
IdleAbilityMissing, IdleAbilityMissing,
#[fail(display = "IMAP select folder error")] #[error("IMAP select folder error")]
SelectFolderError(#[cause] select_folder::Error), SelectFolderError(#[from] select_folder::Error),
#[fail(display = "Setup handle error")] #[error("Setup handle error")]
SetupHandleError(#[cause] super::Error), SetupHandleError(#[from] super::Error),
}
impl From<select_folder::Error> for Error {
fn from(err: select_folder::Error) -> Error {
Error::SelectFolderError(err)
}
} }
#[derive(Debug)] #[derive(Debug)]
@@ -71,9 +65,7 @@ impl Imap {
return Err(Error::IdleAbilityMissing); return Err(Error::IdleAbilityMissing);
} }
self.setup_handle_if_needed(context) self.setup_handle_if_needed(context).await?;
.await
.map_err(Error::SetupHandleError)?;
self.select_folder(context, watch_folder.clone()).await?; self.select_folder(context, watch_folder.clone()).await?;
@@ -84,9 +76,7 @@ impl Imap {
// BEWARE: If you change the Secure branch you // BEWARE: If you change the Secure branch you
// typically also need to change the Insecure branch. // typically also need to change the Insecure branch.
IdleHandle::Secure(mut handle) => { IdleHandle::Secure(mut handle) => {
if let Err(err) = handle.init().await { handle.init().await?;
return Err(Error::IdleProtocolFailed(err));
}
let (idle_wait, interrupt) = handle.wait_with_timeout(timeout); let (idle_wait, interrupt) = handle.wait_with_timeout(timeout);
*self.interrupt.lock().await = Some(interrupt); *self.interrupt.lock().await = Some(interrupt);
@@ -141,9 +131,7 @@ impl Imap {
} }
} }
IdleHandle::Insecure(mut handle) => { IdleHandle::Insecure(mut handle) => {
if let Err(err) = handle.init().await { handle.init().await?;
return Err(Error::IdleProtocolFailed(err));
}
let (idle_wait, interrupt) = handle.wait_with_timeout(timeout); let (idle_wait, interrupt) = handle.wait_with_timeout(timeout);
*self.interrupt.lock().await = Some(interrupt); *self.interrupt.lock().await = Some(interrupt);

View File

@@ -39,78 +39,48 @@ use session::Session;
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Fail)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
#[fail(display = "IMAP Connect without configured params")] #[error("IMAP Connect without configured params")]
ConnectWithoutConfigure, ConnectWithoutConfigure,
#[fail(display = "IMAP Connection Failed params: {}", _0)] #[error("IMAP Connection Failed params: {0}")]
ConnectionFailed(String), ConnectionFailed(String),
#[fail(display = "IMAP No Connection established")] #[error("IMAP No Connection established")]
NoConnection, NoConnection,
#[fail(display = "IMAP Could not get OAUTH token")] #[error("IMAP Could not get OAUTH token")]
OauthError, OauthError,
#[fail(display = "IMAP Could not login as {}", _0)] #[error("IMAP Could not login as {0}")]
LoginFailed(String), LoginFailed(String),
#[fail(display = "IMAP Could not fetch")] #[error("IMAP Could not fetch")]
FetchFailed(#[cause] async_imap::error::Error), FetchFailed(#[from] async_imap::error::Error),
#[fail(display = "IMAP operation attempted while it is torn down")] #[error("IMAP operation attempted while it is torn down")]
InTeardown, InTeardown,
#[fail(display = "IMAP operation attempted while it is torn down")] #[error("IMAP operation attempted while it is torn down")]
SqlError(#[cause] crate::sql::Error), SqlError(#[from] crate::sql::Error),
#[fail(display = "IMAP got error from elsewhere")] #[error("IMAP got error from elsewhere")]
WrappedError(#[cause] crate::error::Error), WrappedError(#[from] crate::error::Error),
#[fail(display = "IMAP select folder error")] #[error("IMAP select folder error")]
SelectFolderError(#[cause] select_folder::Error), SelectFolderError(#[from] select_folder::Error),
#[fail(display = "Mail parse error")] #[error("Mail parse error")]
MailParseError(#[cause] mailparse::MailParseError), MailParseError(#[from] mailparse::MailParseError),
#[fail(display = "No mailbox selected, folder: {:?}", _0)] #[error("No mailbox selected, folder: {0}")]
NoMailbox(String), NoMailbox(String),
#[fail(display = "IMAP other error: {:?}", _0)] #[error("IMAP other error: {0}")]
Other(String), Other(String),
} }
impl From<crate::sql::Error> for Error {
fn from(err: crate::sql::Error) -> Error {
Error::SqlError(err)
}
}
impl From<crate::error::Error> for Error {
fn from(err: crate::error::Error) -> Error {
Error::WrappedError(err)
}
}
impl From<Error> for crate::error::Error {
fn from(err: Error) -> crate::error::Error {
crate::error::Error::Message(err.to_string())
}
}
impl From<select_folder::Error> for Error {
fn from(err: select_folder::Error) -> Error {
Error::SelectFolderError(err)
}
}
impl From<mailparse::MailParseError> for Error {
fn from(err: mailparse::MailParseError) -> Error {
Error::MailParseError(err)
}
}
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Display, Clone, Copy, PartialEq, Eq)]
pub enum ImapActionResult { pub enum ImapActionResult {
Failed, Failed,

View File

@@ -4,21 +4,21 @@ use crate::context::Context;
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Fail)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
#[fail(display = "IMAP Could not obtain imap-session object.")] #[error("IMAP Could not obtain imap-session object.")]
NoSession, NoSession,
#[fail(display = "IMAP Connection Lost or no connection established")] #[error("IMAP Connection Lost or no connection established")]
ConnectionLost, ConnectionLost,
#[fail(display = "IMAP Folder name invalid: {:?}", _0)] #[error("IMAP Folder name invalid: {0}")]
BadFolderName(String), BadFolderName(String),
#[fail(display = "IMAP close/expunge failed: {}", _0)] #[error("IMAP close/expunge failed")]
CloseExpungeFailed(#[cause] async_imap::error::Error), CloseExpungeFailed(#[from] async_imap::error::Error),
#[fail(display = "IMAP other error: {:?}", _0)] #[error("IMAP other error: {0}")]
Other(String), Other(String),
} }

View File

@@ -19,7 +19,7 @@ use crate::constants::*;
use crate::contact::Contact; use crate::contact::Contact;
use crate::context::{Context, PerformJobsNeeded}; use crate::context::{Context, PerformJobsNeeded};
use crate::dc_tools::*; use crate::dc_tools::*;
use crate::error::{Error, Result}; use crate::error::{bail, ensure, format_err, Error, Result};
use crate::events::Event; use crate::events::Event;
use crate::imap::*; use crate::imap::*;
use crate::imex::*; use crate::imex::*;
@@ -227,7 +227,7 @@ impl Job {
// Local error, job is invalid, do not retry. // Local error, job is invalid, do not retry.
smtp.disconnect(); smtp.disconnect();
warn!(context, "SMTP job is invalid: {}", err); warn!(context, "SMTP job is invalid: {}", err);
Status::Finished(Err(Error::SmtpError(err))) Status::Finished(Err(err.into()))
} }
Err(crate::smtp::send::Error::NoTransport) => { Err(crate::smtp::send::Error::NoTransport) => {
// Should never happen. // Should never happen.

View File

@@ -1,7 +1,7 @@
use std::sync::{Arc, Condvar, Mutex}; use std::sync::{Arc, Condvar, Mutex};
use crate::context::Context; use crate::context::Context;
use crate::error::{Error, Result}; use crate::error::{format_err, Result};
use crate::imap::Imap; use crate::imap::Imap;
#[derive(Debug)] #[derive(Debug)]
@@ -99,25 +99,21 @@ impl JobThread {
async fn connect_and_fetch(&mut self, context: &Context) -> Result<()> { async fn connect_and_fetch(&mut self, context: &Context) -> Result<()> {
let prefix = format!("{}-fetch", self.name); let prefix = format!("{}-fetch", self.name);
match self.imap.connect_configured(context) { self.imap.connect_configured(context)?;
Ok(()) => { if let Some(watch_folder) = self.get_watch_folder(context) {
if let Some(watch_folder) = self.get_watch_folder(context) { let start = std::time::Instant::now();
let start = std::time::Instant::now(); info!(context, "{} started...", prefix);
info!(context, "{} started...", prefix); let res = self
let res = self .imap
.imap .fetch(context, &watch_folder)
.fetch(context, &watch_folder) .await
.await .map_err(Into::into);
.map_err(Into::into); let elapsed = start.elapsed().as_millis();
let elapsed = start.elapsed().as_millis(); info!(context, "{} done in {:.3} ms.", prefix, elapsed);
info!(context, "{} done in {:.3} ms.", prefix, elapsed);
res res
} else { } else {
Err(Error::WatchFolderNotFound("not-set".to_string())) Err(format_err!("WatchFolder not found: not-set"))
}
}
Err(err) => Err(crate::error::Error::Message(err.to_string())),
} }
} }

View File

@@ -18,24 +18,12 @@ pub use crate::pgp::KeyPair;
pub use pgp::composed::{SignedPublicKey, SignedSecretKey}; pub use pgp::composed::{SignedPublicKey, SignedSecretKey};
/// Error type for deltachat key handling. /// Error type for deltachat key handling.
#[derive(Fail, Debug)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
#[fail(display = "Could not decode base64")] #[error("Could not decode base64")]
Base64Decode(#[cause] base64::DecodeError, failure::Backtrace), Base64Decode(#[from] base64::DecodeError),
#[fail(display = "rPGP error: {}", _0)] #[error("rPGP error: {0}")]
PgpError(#[cause] pgp::errors::Error, failure::Backtrace), PgpError(#[from] pgp::errors::Error),
}
impl From<base64::DecodeError> for Error {
fn from(err: base64::DecodeError) -> Error {
Error::Base64Decode(err, failure::Backtrace::new())
}
}
impl From<pgp::errors::Error> for Error {
fn from(err: pgp::errors::Error) -> Error {
Error::PgpError(err, failure::Backtrace::new())
}
} }
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
@@ -316,21 +304,19 @@ pub enum KeyPairUse {
} }
/// Error saving a keypair to the database. /// Error saving a keypair to the database.
#[derive(Fail, Debug)] #[derive(Debug, thiserror::Error)]
#[fail(display = "SaveKeyError: {}", message)] #[error("SaveKeyError: {message}")]
pub struct SaveKeyError { pub struct SaveKeyError {
message: String, message: String,
#[cause] #[source]
cause: failure::Error, cause: anyhow::Error,
backtrace: failure::Backtrace,
} }
impl SaveKeyError { impl SaveKeyError {
fn new(message: impl Into<String>, cause: impl Into<failure::Error>) -> Self { fn new(message: impl Into<String>, cause: impl Into<anyhow::Error>) -> Self {
Self { Self {
message: message.into(), message: message.into(),
cause: cause.into(), cause: cause.into(),
backtrace: failure::Backtrace::new(),
} }
} }
} }

View File

@@ -2,8 +2,6 @@
#![deny(clippy::correctness, missing_debug_implementations, clippy::all)] #![deny(clippy::correctness, missing_debug_implementations, clippy::all)]
#![allow(clippy::match_bool)] #![allow(clippy::match_bool)]
#[macro_use]
extern crate failure_derive;
#[macro_use] #[macro_use]
extern crate num_derive; extern crate num_derive;
#[macro_use] #[macro_use]

View File

@@ -9,7 +9,7 @@ use crate::config::Config;
use crate::constants::*; use crate::constants::*;
use crate::context::*; use crate::context::*;
use crate::dc_tools::*; use crate::dc_tools::*;
use crate::error::Error; use crate::error::{ensure, Error};
use crate::events::Event; use crate::events::Event;
use crate::job::{self, job_action_exists, job_add, Job}; use crate::job::{self, job_action_exists, job_add, Job};
use crate::message::{Message, MsgId}; use crate::message::{Message, MsgId};

View File

@@ -3,7 +3,6 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use deltachat_derive::{FromSql, ToSql}; use deltachat_derive::{FromSql, ToSql};
use failure::Fail;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -12,7 +11,7 @@ use crate::constants::*;
use crate::contact::*; use crate::contact::*;
use crate::context::*; use crate::context::*;
use crate::dc_tools::*; use crate::dc_tools::*;
use crate::error::Error; use crate::error::{ensure, Error};
use crate::events::Event; use crate::events::Event;
use crate::job::*; use crate::job::*;
use crate::lot::{Lot, LotState, Meaning}; use crate::lot::{Lot, LotState, Meaning};
@@ -170,7 +169,7 @@ impl rusqlite::types::ToSql for MsgId {
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> { fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
if self.0 <= DC_MSG_ID_LAST_SPECIAL { if self.0 <= DC_MSG_ID_LAST_SPECIAL {
return Err(rusqlite::Error::ToSqlConversionFailure(Box::new( return Err(rusqlite::Error::ToSqlConversionFailure(Box::new(
InvalidMsgId.compat(), InvalidMsgId,
))); )));
} }
let val = rusqlite::types::Value::Integer(self.0 as i64); let val = rusqlite::types::Value::Integer(self.0 as i64);
@@ -198,8 +197,8 @@ impl rusqlite::types::FromSql for MsgId {
/// This usually occurs when trying to use a message ID of /// This usually occurs when trying to use a message ID of
/// [DC_MSG_ID_LAST_SPECIAL] or below in a situation where this is not /// [DC_MSG_ID_LAST_SPECIAL] or below in a situation where this is not
/// possible. /// possible.
#[derive(Debug, Fail)] #[derive(Debug, thiserror::Error)]
#[fail(display = "Invalid Message ID.")] #[error("Invalid Message ID.")]
pub struct InvalidMsgId; pub struct InvalidMsgId;
#[derive( #[derive(

View File

@@ -9,7 +9,7 @@ use crate::contact::*;
use crate::context::{get_version_str, Context}; use crate::context::{get_version_str, Context};
use crate::dc_tools::*; use crate::dc_tools::*;
use crate::e2ee::*; use crate::e2ee::*;
use crate::error::Error; use crate::error::{bail, ensure, format_err, Error};
use crate::location; use crate::location;
use crate::message::{self, Message}; use crate::message::{self, Message};
use crate::mimeparser::SystemMessage; use crate::mimeparser::SystemMessage;

View File

@@ -1,11 +1,11 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use anyhow::Context as _;
use deltachat_derive::{FromSql, ToSql}; use deltachat_derive::{FromSql, ToSql};
use lettre_email::mime::{self, Mime}; use lettre_email::mime::{self, Mime};
use mailparse::{DispositionType, MailAddr, MailHeaderMap}; use mailparse::{DispositionType, MailAddr, MailHeaderMap};
use crate::aheader::Aheader; use crate::aheader::Aheader;
use crate::bail;
use crate::blob::BlobObject; use crate::blob::BlobObject;
use crate::constants::Viewtype; use crate::constants::Viewtype;
use crate::contact::*; use crate::contact::*;
@@ -13,7 +13,7 @@ use crate::context::Context;
use crate::dc_tools::*; use crate::dc_tools::*;
use crate::dehtml::dehtml; use crate::dehtml::dehtml;
use crate::e2ee; use crate::e2ee;
use crate::error::Result; use crate::error::{bail, Result};
use crate::events::Event; use crate::events::Event;
use crate::headerdef::{HeaderDef, HeaderDefMap}; use crate::headerdef::{HeaderDef, HeaderDefMap};
use crate::location; use crate::location;
@@ -884,8 +884,7 @@ pub(crate) struct Report {
} }
pub(crate) fn parse_message_id(value: &str) -> crate::error::Result<String> { pub(crate) fn parse_message_id(value: &str) -> crate::error::Result<String> {
let ids = mailparse::msgidparse(value) let ids = mailparse::msgidparse(value).context("failed to parse message id")?;
.map_err(|err| format_err!("failed to parse message id {:?}", err))?;
if let Some(id) = ids.first() { if let Some(id) = ids.first() {
Ok(id.to_string()) Ok(id.to_string())

View File

@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use crate::blob::{BlobError, BlobObject}; use crate::blob::{BlobError, BlobObject};
use crate::context::Context; use crate::context::Context;
use crate::error; use crate::error::{self, bail, ensure};
use crate::message::MsgId; use crate::message::MsgId;
use crate::mimeparser::SystemMessage; use crate::mimeparser::SystemMessage;

View File

@@ -18,7 +18,7 @@ use rand::{thread_rng, CryptoRng, Rng};
use crate::constants::KeyGenType; use crate::constants::KeyGenType;
use crate::dc_tools::EmailAddress; use crate::dc_tools::EmailAddress;
use crate::error::Result; use crate::error::{bail, ensure, format_err, Result};
use crate::key::*; use crate::key::*;
use crate::keyring::*; use crate::keyring::*;
@@ -117,21 +117,19 @@ pub fn split_armored_data(buf: &[u8]) -> Result<(BlockType, BTreeMap<String, Str
/// ///
/// Most of these are likely coding errors rather than user errors /// Most of these are likely coding errors rather than user errors
/// since all variability is hardcoded. /// since all variability is hardcoded.
#[derive(Fail, Debug)] #[derive(Debug, thiserror::Error)]
#[fail(display = "PgpKeygenError: {}", message)] #[error("PgpKeygenError: {message}")]
pub(crate) struct PgpKeygenError { pub(crate) struct PgpKeygenError {
message: String, message: String,
#[cause] #[source]
cause: failure::Error, cause: anyhow::Error,
backtrace: failure::Backtrace,
} }
impl PgpKeygenError { impl PgpKeygenError {
fn new(message: impl Into<String>, cause: impl Into<failure::Error>) -> Self { fn new(message: impl Into<String>, cause: impl Into<anyhow::Error>) -> Self {
Self { Self {
message: message.into(), message: message.into(),
cause: cause.into(), cause: cause.into(),
backtrace: failure::Backtrace::new(),
} }
} }
} }
@@ -189,7 +187,7 @@ pub(crate) fn create_keypair(
.unwrap(), .unwrap(),
) )
.build() .build()
.map_err(|err| PgpKeygenError::new("invalid key params", failure::err_msg(err)))?; .map_err(|err| PgpKeygenError::new("invalid key params", format_err!(err)))?;
let key = key_params let key = key_params
.generate() .generate()
.map_err(|err| PgpKeygenError::new("invalid params", err))?; .map_err(|err| PgpKeygenError::new("invalid params", err))?;

View File

@@ -2,20 +2,20 @@
use lazy_static::lazy_static; use lazy_static::lazy_static;
use percent_encoding::percent_decode_str; use percent_encoding::percent_decode_str;
use reqwest::Url;
use serde::Deserialize;
use crate::chat; use crate::chat;
use crate::config::*; use crate::config::*;
use crate::constants::Blocked; use crate::constants::Blocked;
use crate::contact::*; use crate::contact::*;
use crate::context::Context; use crate::context::Context;
use crate::error::Error; use crate::error::{bail, ensure, format_err, Error};
use crate::key::dc_format_fingerprint; use crate::key::dc_format_fingerprint;
use crate::key::dc_normalize_fingerprint; use crate::key::dc_normalize_fingerprint;
use crate::lot::{Lot, LotState}; use crate::lot::{Lot, LotState};
use crate::param::*; use crate::param::*;
use crate::peerstate::*; use crate::peerstate::*;
use reqwest::Url;
use serde::Deserialize;
const OPENPGP4FPR_SCHEME: &str = "OPENPGP4FPR:"; // yes: uppercase const OPENPGP4FPR_SCHEME: &str = "OPENPGP4FPR:"; // yes: uppercase
const DCACCOUNT_SCHEME: &str = "DCACCOUNT:"; const DCACCOUNT_SCHEME: &str = "DCACCOUNT:";
@@ -221,27 +221,20 @@ pub fn set_config_from_qr(context: &Context, qr: &str) -> Result<(), Error> {
let response = reqwest::blocking::Client::new().post(url_str).send(); let response = reqwest::blocking::Client::new().post(url_str).send();
if response.is_err() { if response.is_err() {
return Err(format_err!( bail!("Cannot create account, request to {} failed", url_str);
"Cannot create account, request to {} failed",
url_str
));
} }
let response = response.unwrap(); let response = response.unwrap();
if !response.status().is_success() { if !response.status().is_success() {
return Err(format_err!( bail!("Request to {} unsuccessful: {:?}", url_str, response);
"Request to {} unsuccessful: {:?}",
url_str,
response
));
} }
let parsed: reqwest::Result<CreateAccountResponse> = response.json(); let parsed: reqwest::Result<CreateAccountResponse> = response.json();
if parsed.is_err() { if parsed.is_err() {
return Err(format_err!( bail!(
"Failed to parse JSON response from {}: error: {:?}", "Failed to parse JSON response from {}: error: {:?}",
url_str, url_str,
parsed parsed
)); );
} }
println!("response: {:?}", &parsed); println!("response: {:?}", &parsed);
let parsed = parsed.unwrap(); let parsed = parsed.unwrap();
@@ -289,7 +282,6 @@ fn decode_smtp(context: &Context, qr: &str) -> Lot {
Ok(addr) => addr, Ok(addr) => addr,
Err(err) => return err.into(), Err(err) => return err.into(),
}; };
let name = "".to_string(); let name = "".to_string();
Lot::from_address(context, name, addr) Lot::from_address(context, name, addr)
} }

View File

@@ -9,7 +9,7 @@ use crate::constants::*;
use crate::contact::*; use crate::contact::*;
use crate::context::Context; use crate::context::Context;
use crate::e2ee::*; use crate::e2ee::*;
use crate::error::Error; use crate::error::{bail, Error};
use crate::events::Event; use crate::events::Event;
use crate::headerdef::HeaderDef; use crate::headerdef::HeaderDef;
use crate::key::{dc_normalize_fingerprint, Key}; use crate::key::{dc_normalize_fingerprint, Key};
@@ -343,24 +343,21 @@ fn fingerprint_equals_sender(
} }
false false
} }
#[derive(Fail, Debug)] #[derive(Debug, thiserror::Error)]
pub(crate) enum HandshakeError { pub(crate) enum HandshakeError {
#[fail(display = "Can not be called with special contact ID")] #[error("Can not be called with special contact ID")]
SpecialContactId, SpecialContactId,
#[fail(display = "Not a Secure-Join message")] #[error("Not a Secure-Join message")]
NotSecureJoinMsg, NotSecureJoinMsg,
#[fail( #[error("Failed to look up or create chat for contact #{contact_id}")]
display = "Failed to look up or create chat for contact #{}",
contact_id
)]
NoChat { NoChat {
contact_id: u32, contact_id: u32,
#[cause] #[source]
cause: Error, cause: Error,
}, },
#[fail(display = "Chat for group {} not found", group)] #[error("Chat for group {group} not found")]
ChatNotFound { group: String }, ChatNotFound { group: String },
#[fail(display = "No configured self address found")] #[error("No configured self address found")]
NoSelfAddr, NoSelfAddr,
} }

View File

@@ -16,35 +16,29 @@ use crate::oauth2::*;
/// SMTP write and read timeout in seconds. /// SMTP write and read timeout in seconds.
const SMTP_TIMEOUT: u64 = 30; const SMTP_TIMEOUT: u64 = 30;
#[derive(Debug, Fail)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
#[fail(display = "Bad parameters")] #[error("Bad parameters")]
BadParameters, BadParameters,
#[fail(display = "Invalid login address {}: {}", address, error)] #[error("Invalid login address {address}: {error}")]
InvalidLoginAddress { InvalidLoginAddress {
address: String, address: String,
#[cause] #[source]
error: error::Error, error: error::Error,
}, },
#[fail(display = "SMTP failed to connect: {:?}", _0)] #[error("SMTP: failed to connect: {0:?}")]
ConnectionFailure(#[cause] smtp::error::Error), ConnectionFailure(#[source] smtp::error::Error),
#[fail(display = "SMTP: failed to setup connection {:?}", _0)] #[error("SMTP: failed to setup connection {0:?}")]
ConnectionSetupFailure(#[cause] smtp::error::Error), ConnectionSetupFailure(#[source] smtp::error::Error),
#[fail(display = "SMTP: oauth2 error {:?}", _0)] #[error("SMTP: oauth2 error {address}")]
Oauth2Error { address: String }, Oauth2Error { address: String },
#[fail(display = "TLS error")] #[error("TLS error")]
Tls(#[cause] async_native_tls::Error), Tls(#[from] async_native_tls::Error),
}
impl From<async_native_tls::Error> for Error {
fn from(err: async_native_tls::Error) -> Error {
Error::Tls(err)
}
} }
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;

View File

@@ -8,15 +8,15 @@ use crate::events::Event;
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Fail)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
#[fail(display = "Envelope error: {}", _0)] #[error("Envelope error: {}", _0)]
EnvelopeError(#[cause] async_smtp::error::Error), EnvelopeError(#[from] async_smtp::error::Error),
#[fail(display = "Send error: {}", _0)] #[error("Send error: {}", _0)]
SendError(#[cause] async_smtp::smtp::error::Error), SendError(#[from] async_smtp::smtp::error::Error),
#[fail(display = "SMTP has no transport")] #[error("SMTP has no transport")]
NoTransport, NoTransport,
} }

View File

@@ -14,50 +14,28 @@ use crate::dc_tools::*;
use crate::param::*; use crate::param::*;
use crate::peerstate::*; use crate::peerstate::*;
#[derive(Debug, Fail)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
#[fail(display = "Sqlite Error: {:?}", _0)] #[error("Sqlite Error: {0:?}")]
Sql(#[cause] rusqlite::Error), Sql(#[from] rusqlite::Error),
#[fail(display = "Sqlite Connection Pool Error: {:?}", _0)] #[error("Sqlite Connection Pool Error: {0:?}")]
ConnectionPool(#[cause] r2d2::Error), ConnectionPool(#[from] r2d2::Error),
#[fail(display = "Sqlite: Connection closed")] #[error("Sqlite: Connection closed")]
SqlNoConnection, SqlNoConnection,
#[fail(display = "Sqlite: Already open")] #[error("Sqlite: Already open")]
SqlAlreadyOpen, SqlAlreadyOpen,
#[fail(display = "Sqlite: Failed to open")] #[error("Sqlite: Failed to open")]
SqlFailedToOpen, SqlFailedToOpen,
#[fail(display = "{:?}", _0)] #[error("{0}")]
Io(#[cause] std::io::Error), Io(#[from] std::io::Error),
#[fail(display = "{:?}", _0)] #[error("{0:?}")]
BlobError(#[cause] crate::blob::BlobError), BlobError(#[from] crate::blob::BlobError),
#[error("{0}")]
Other(#[from] crate::error::Error),
} }
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
impl From<rusqlite::Error> for Error {
fn from(err: rusqlite::Error) -> Error {
Error::Sql(err)
}
}
impl From<r2d2::Error> for Error {
fn from(err: r2d2::Error) -> Error {
Error::ConnectionPool(err)
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Error {
Error::Io(err)
}
}
impl From<crate::blob::BlobError> for Error {
fn from(err: crate::blob::BlobError) -> Error {
Error::BlobError(err)
}
}
/// A wrapper around the underlying Sqlite3 object. /// A wrapper around the underlying Sqlite3 object.
#[derive(DebugStub)] #[derive(DebugStub)]
pub struct Sql { pub struct Sql {
@@ -96,7 +74,7 @@ impl Sql {
pub fn open(&self, context: &Context, dbfile: &std::path::Path, readonly: bool) -> bool { pub fn open(&self, context: &Context, dbfile: &std::path::Path, readonly: bool) -> bool {
match open(context, self, dbfile, readonly) { match open(context, self, dbfile, readonly) {
Ok(_) => true, Ok(_) => true,
Err(crate::error::Error::SqlError(Error::SqlAlreadyOpen)) => false, Err(Error::SqlAlreadyOpen) => false,
Err(_) => { Err(_) => {
self.close(context); self.close(context);
false false
@@ -388,14 +366,14 @@ fn open(
sql: &Sql, sql: &Sql,
dbfile: impl AsRef<std::path::Path>, dbfile: impl AsRef<std::path::Path>,
readonly: bool, readonly: bool,
) -> crate::error::Result<()> { ) -> Result<()> {
if sql.is_open() { if sql.is_open() {
error!( error!(
context, context,
"Cannot open, database \"{:?}\" already opened.", "Cannot open, database \"{:?}\" already opened.",
dbfile.as_ref(), dbfile.as_ref(),
); );
return Err(Error::SqlAlreadyOpen.into()); return Err(Error::SqlAlreadyOpen);
} }
let mut open_flags = OpenFlags::SQLITE_OPEN_NO_MUTEX; let mut open_flags = OpenFlags::SQLITE_OPEN_NO_MUTEX;
@@ -545,7 +523,7 @@ fn open(
dbfile.as_ref(), dbfile.as_ref(),
); );
// cannot create the tables - maybe we cannot write? // cannot create the tables - maybe we cannot write?
return Err(Error::SqlFailedToOpen.into()); return Err(Error::SqlFailedToOpen);
} else { } else {
sql.set_raw_config_int(context, "dbversion", 0)?; sql.set_raw_config_int(context, "dbversion", 0)?;
} }

View File

@@ -10,7 +10,7 @@ use crate::chat;
use crate::constants::{Viewtype, DC_CONTACT_ID_SELF}; use crate::constants::{Viewtype, DC_CONTACT_ID_SELF};
use crate::contact::*; use crate::contact::*;
use crate::context::Context; use crate::context::Context;
use crate::error::Error; use crate::error::{bail, Error};
use crate::message::Message; use crate::message::Message;
use crate::param::Param; use crate::param::Param;
use crate::stock::StockMessage::{DeviceMessagesHint, WelcomeMessage}; use crate::stock::StockMessage::{DeviceMessagesHint, WelcomeMessage};