Normalize panic message
Change all unwrap to expect Normalize expect's messages Don't panic where it could be avoided easily
This commit is contained in:
@@ -37,10 +37,10 @@ impl Reshare {
|
||||
diesel::update(self)
|
||||
.set(reshares::ap_url.eq(format!(
|
||||
"{}/reshare/{}",
|
||||
User::get(conn, self.user_id).unwrap().ap_url,
|
||||
Post::get(conn, self.post_id).unwrap().ap_url
|
||||
User::get(conn, self.user_id).expect("Reshare::update_ap_url: user error").ap_url,
|
||||
Post::get(conn, self.post_id).expect("Reshare::update_ap_url: post error").ap_url
|
||||
)))
|
||||
.execute(conn).expect("Couldn't update AP URL");
|
||||
.execute(conn).expect("Reshare::update_ap_url: update error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ impl Reshare {
|
||||
.order(reshares::creation_date.desc())
|
||||
.limit(limit)
|
||||
.load::<Reshare>(conn)
|
||||
.expect("Error loading recent reshares for user")
|
||||
.expect("Reshare::get_recents_for_author: loading error")
|
||||
}
|
||||
|
||||
pub fn get_post(&self, conn: &Connection) -> Option<Post> {
|
||||
@@ -62,9 +62,11 @@ impl Reshare {
|
||||
|
||||
pub fn into_activity(&self, conn: &Connection) -> Announce {
|
||||
let mut act = Announce::default();
|
||||
act.announce_props.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.announce_props.set_object_link(Post::get(conn, self.post_id).unwrap().into_id()).unwrap();
|
||||
act.object_props.set_id_string(self.ap_url.clone()).unwrap();
|
||||
act.announce_props.set_actor_link(User::get(conn, self.user_id).expect("Reshare::into_activity: user error").into_id())
|
||||
.expect("Reshare::into_activity: actor error");
|
||||
act.announce_props.set_object_link(Post::get(conn, self.post_id).expect("Reshare::into_activity: post error").into_id())
|
||||
.expect("Reshare::into_activity: object error");
|
||||
act.object_props.set_id_string(self.ap_url.clone()).expect("Reshare::into_activity: id error");
|
||||
act.object_props.set_to_link(Id::new(PUBLIC_VISIBILTY.to_string())).expect("Reshare::into_activity: to error");
|
||||
act.object_props.set_cc_link_vec::<Id>(vec![]).expect("Reshare::into_activity: cc error");
|
||||
|
||||
@@ -77,8 +79,8 @@ impl FromActivity<Announce, Connection> for Reshare {
|
||||
let user = User::from_url(conn, announce.announce_props.actor_link::<Id>().expect("Reshare::from_activity: actor error").into());
|
||||
let post = Post::find_by_ap_url(conn, announce.announce_props.object_link::<Id>().expect("Reshare::from_activity: object error").into());
|
||||
let reshare = Reshare::insert(conn, NewReshare {
|
||||
post_id: post.unwrap().id,
|
||||
user_id: user.unwrap().id,
|
||||
post_id: post.expect("Reshare::from_activity: post error").id,
|
||||
user_id: user.expect("Reshare::from_activity: user error").id,
|
||||
ap_url: announce.object_props.id_string().unwrap_or(String::from(""))
|
||||
});
|
||||
reshare.notify(conn);
|
||||
@@ -88,7 +90,7 @@ impl FromActivity<Announce, Connection> for Reshare {
|
||||
|
||||
impl Notify<Connection> for Reshare {
|
||||
fn notify(&self, conn: &Connection) {
|
||||
let post = self.get_post(conn).unwrap();
|
||||
let post = self.get_post(conn).expect("Reshare::notify: post error");
|
||||
for author in post.get_authors(conn) {
|
||||
Notification::insert(conn, NewNotification {
|
||||
kind: notification_kind::RESHARE.to_string(),
|
||||
@@ -101,16 +103,16 @@ impl Notify<Connection> for Reshare {
|
||||
|
||||
impl Deletable<Connection, Undo> for Reshare {
|
||||
fn delete(&self, conn: &Connection) -> Undo {
|
||||
diesel::delete(self).execute(conn).unwrap();
|
||||
diesel::delete(self).execute(conn).expect("Reshare::delete: delete error");
|
||||
|
||||
// delete associated notification if any
|
||||
if let Some(notif) = Notification::find(conn, notification_kind::RESHARE, self.id) {
|
||||
diesel::delete(¬if).execute(conn).expect("Couldn't delete reshare notification");
|
||||
diesel::delete(¬if).execute(conn).expect("Reshare::delete: notification error");
|
||||
}
|
||||
|
||||
let mut act = Undo::default();
|
||||
act.undo_props.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.undo_props.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act.undo_props.set_actor_link(User::get(conn, self.user_id).expect("Reshare::delete: user error").into_id()).expect("Reshare::delete: actor error");
|
||||
act.undo_props.set_object_object(self.into_activity(conn)).expect("Reshare::delete: object error");
|
||||
act.object_props.set_id_string(format!("{}#delete", self.ap_url)).expect("Reshare::delete: id error");
|
||||
act.object_props.set_to_link(Id::new(PUBLIC_VISIBILTY.to_string())).expect("Reshare::delete: to error");
|
||||
act.object_props.set_cc_link_vec::<Id>(vec![]).expect("Reshare::delete: cc error");
|
||||
|
||||
Reference in New Issue
Block a user