Commit 59fdbf32 authored by lorenzo's avatar lorenzo Committed by lorenzo

Simpler error handling

parent 6b06c444
......@@ -411,28 +411,6 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "298f00c3b04c1d9b4cb86aefaaa35348af0957d98b30a5306fc635f8e718923d"
[[package]]
name = "failure"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
dependencies = [
"backtrace",
"failure_derive",
]
[[package]]
name = "failure_derive"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2",
"quote",
"syn",
"synstructure",
]
[[package]]
name = "fastrand"
version = "1.3.3"
......@@ -1883,8 +1861,6 @@ dependencies = [
"chrono",
"diesel",
"diesel_migrations",
"failure",
"failure_derive",
"futures",
"futures-io",
"futures-util",
......@@ -1915,6 +1891,7 @@ dependencies = [
"serde_urlencoded",
"strum",
"strum_macros",
"thiserror",
"url",
]
......@@ -2004,18 +1981,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "synstructure"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701"
dependencies = [
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]]
name = "system-deps"
version = "1.3.2"
......
......@@ -20,8 +20,6 @@ matches = "0.1.8"
open = "1.3.2"
url = "2.1.0"
indexmap = "1.3.0"
failure = "0.1.6"
failure_derive = "0.1.6"
strum = "0.18"
strum_macros = "0.18"
diesel_migrations = "1.4.0"
......@@ -32,6 +30,7 @@ futures-util = "0.3.1"
async-std = "1.4.0"
isahc = "0.9"
regex = "1.3.4"
thiserror = "1.0"
gstreamer = { version = "0.16.1", features = ["v1_10"] }
gstreamer-audio = "0.16.0"
......
......@@ -14,55 +14,31 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#[derive(Fail, Debug)]
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[fail(display = "Serde error: {}", _0)]
SerdeError(#[cause] serde_json::error::Error),
#[error("Serde error: {0}")]
SerdeError(#[from] serde_json::error::Error),
#[fail(display = "URL parser error: {}", _0)]
UrlParseError(#[cause] url::ParseError),
#[error("URL parser error: {0}")]
UrlParseError(#[from] url::ParseError),
#[fail(display = "GLib Error: {}", _0)]
GLibError(#[cause] glib::error::Error),
#[error("GLib Error: {0}")]
GLibError(#[from] glib::error::Error),
#[fail(display = "Input/Output error.")]
IOError(#[cause] std::io::Error),
#[error("Input/Output error: {0}")]
IOError(#[from] std::io::Error),
#[fail(display = "Network error: {}", _0)]
NetworkError(#[cause] isahc::Error),
#[error("Network error: {0}")]
NetworkError(#[from] isahc::Error),
#[fail(display = "Database error: {}", _0)]
DieselError(#[cause] diesel::result::Error),
#[error("Database error: {0}")]
DieselError(#[from] diesel::result::Error),
#[fail(display = "Invalid station UUID")]
#[error("Invalid station UUID: {0}")]
InvalidStationError(String),
#[fail(display = "Cache error")]
#[error("Cache error")]
CacheError,
}
// Maps a type to a variant of the Error enum
// Source: https://gitlab.gnome.org/World/podcasts/blob/945b40249cdf41d9c9766938f455e204ff88906e/podcasts-data/src/errors.rs#L94
macro_rules! easy_from_impl {
($outer_type:ty, $from:ty => $to:expr) => (
impl From<$from> for $outer_type {
fn from(err: $from) -> Self {
$to(err)
}
}
);
($outer_type:ty, $from:ty => $to:expr, $($f:ty => $t:expr),+) => (
easy_from_impl!($outer_type, $from => $to);
easy_from_impl!($outer_type, $($f => $t),+);
);
}
easy_from_impl!(
Error,
serde_json::error::Error => Error::SerdeError,
glib::error::Error => Error::GLibError,
url::ParseError => Error::UrlParseError,
std::io::Error => Error::IOError,
isahc::Error => Error::NetworkError,
diesel::result::Error => Error::DieselError
);
......@@ -26,8 +26,6 @@ extern crate matches;
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate failure_derive;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate strum_macros;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment