Skip to content

Commit

Permalink
better error showing
Browse files Browse the repository at this point in the history
  • Loading branch information
AdriDevelopsThings committed Jan 1, 2023
1 parent cc555d6 commit 9cef742
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iceportal_rich_presense"
version = "1.0.1"
version = "1.0.2"
edition = "2021"
authors = ["AdriDevelopsThings"]
readme = "README.md"
Expand All @@ -11,6 +11,6 @@ description = "Show your current ride in discord via the ICE portal api"

[dependencies]
discord-rich-presence = "0.2.3"
iceportal = "2.0.0"
iceportal = "2.0.1"
inquire = "0.5.2"
tokio = { version = "1", features = ["full"] }
22 changes: 22 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::fmt::Debug;

use iceportal::errors::ICEPortalError;

pub enum ICEPortalRichPresenseError {
ICEPortalError(ICEPortalError)
}

impl From<ICEPortalError> for ICEPortalRichPresenseError {
fn from(e: ICEPortalError) -> Self {
Self::ICEPortalError(e)
}
}

impl Debug for ICEPortalRichPresenseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ICEPortalError(_) =>
write!(f, "Error while connecting to ICE portal: Please check if you are connected to the Bahn WiFi")
}
}
}
14 changes: 8 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::{time::Duration, process::exit};

use discord_rich_presence::{DiscordIpcClient, DiscordIpc, activity::{self, Activity, Timestamps, Assets, Button}};
use errors::ICEPortalRichPresenseError;
use iceportal::{ICEPortal, trip_info::TripInfo, global_models::{PositionStatus, Stop}};
use inquire::Select;
use tokio::{select, time::sleep};

mod errors;

fn cancel_activity(client: &mut DiscordIpcClient) {
client.clear_activity().expect("Error while clearing activity");
}
Expand Down Expand Up @@ -40,11 +43,9 @@ fn update_activity(client: &mut DiscordIpcClient, trip: TripInfo, to: &str, buil
}

#[tokio::main]
async fn main() {
let trip_info = ICEPortal::fetch_trip_info().await
.expect("Error while fetching iceportal data");
let status_info = ICEPortal::fetch_status().await
.expect("Error while fetching iceportal data");
async fn main() -> Result<(), ICEPortalRichPresenseError>{
let trip_info = ICEPortal::fetch_trip_info().await?;
let status_info = ICEPortal::fetch_status().await?;
let available_stops = trip_info.trip.stops.iter()
.filter(|stop| stop.info.position_status.is_none() || stop.info.position_status == Some(PositionStatus::Future))
.map(|stop| stop.station.name.as_str()).collect::<Vec<&str>>();
Expand All @@ -60,7 +61,7 @@ async fn main() {
let (trip_info_sender, mut trip_info_receiver) = tokio::sync::mpsc::unbounded_channel();
tokio::spawn(async move {
loop {
let trip_info = ICEPortal::fetch_trip_info().await.expect("Error while fetching trip info");
let trip_info = ICEPortal::fetch_trip_info().await.unwrap();
trip_info_sender.send(trip_info)
.expect("Error while putting message to trip_info channel");
sleep(Duration::from_secs(30)).await;
Expand Down Expand Up @@ -91,4 +92,5 @@ async fn main() {
},
}
}
Ok(())
}

0 comments on commit 9cef742

Please sign in to comment.