Skip to content

Commit

Permalink
Fix panic when running into posts which cannot be retrieved from the …
Browse files Browse the repository at this point in the history
…API during GDPR run (#70)
  • Loading branch information
andrewbanchich authored Jun 25, 2023
1 parent 4d17f6a commit dd8d025
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ impl Config {
} else if self.dry_run {
debug!("Skipping DELETION due to 'dry run' filter");
}
return self.edit_only | self.dry_run;
self.edit_only | self.dry_run
}
}
20 changes: 14 additions & 6 deletions src/things/comment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::Shred;
use super::{Shred, ShredditError};
use crate::{
cli::Config,
sources::{api::Api, gdpr::Gdpr},
Expand Down Expand Up @@ -147,7 +147,10 @@ impl Shred for Comment {
}
}
Source::Gdpr { .. } => {
let comment = self.to_api(client, access_token, config).await;
let Ok(comment) = self.to_api(client, access_token, config).await else {
return
};

match comment.source {
Source::Api { can_gild, .. } => {
if !can_gild {
Expand Down Expand Up @@ -213,7 +216,12 @@ impl Comment {
false
}

async fn to_api(&self, client: &Client, access_token: &str, config: &Config) -> Self {
async fn to_api(
&self,
client: &Client,
access_token: &str,
config: &Config,
) -> Result<Self, ShredditError> {
debug!("Getting comment from API...");

let mut headers = HeaderMap::new();
Expand All @@ -240,10 +248,10 @@ impl Comment {
.unwrap();

match res {
Response::Success { data } => data.children.into_iter().next().unwrap().data,
Response::Success { data } => Ok(data.children.into_iter().next().unwrap().data),
Response::Error(e) => {
error!("{e:#?}");
todo!();
error!("Couldn't get comment from API: {e:#?}");
Err(ShredditError::Unknown)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/things/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub static LOREM_IPSUM: &str = "Lorem ipsum dolor sit amet, consectetur adipisci
pub enum ShredditError {
#[allow(dead_code)]
RateLimited,
Unknown,
}

#[derive(Debug, Deserialize, PartialEq, Clone, ValueEnum)]
Expand Down

0 comments on commit dd8d025

Please sign in to comment.