Remove usage of Option::unwrap() in activitypub code #80
No reviewers
Labels
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Blocks
#81 Remove dead code
LemmyNet/lemmy
Reference: LemmyNet/lemmy#80
Loading…
Reference in New Issue
No description provided.
Delete Branch "apub-remove-unwrap"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This removes most usage of
Option::unwrap()
from activitypub code, and replaces it withcontext(location_info!())?
. If a none value is accessed, it will now throw an error like this:TODO:
WIP: Remove usage of Option::unwrap() in activitypub codeto Remove usage of Option::unwrap() in activitypub codeI removed all remaining usage of unwrap() in the apub code so this is good to merge. I also looked into doing the same in other code, but unwrap usages there seem more complicated, so I decided not to touch that.
Note that I came across two ways we can easily simplify the code:
Getting the unwrap was really much easier than I thought.
@ -345,0 +349,4 @@
PublicKey {
id: format!("{}#main-key", self.actor_id_str()),
owner: self.actor_id_str(),
public_key_pem: self.public_key().context(location_info!())?,
Nice, this is a pretty easy way to do this.
@ -320,0 +317,4 @@
let actor_id = self.actor_id()?;
let url = format!(
"{}://{}{}/inbox",
&actor_id.scheme(),
Cool, so we do get some url functionality out of this.
What do you mean get some url functionality?
@ -147,6 +148,37 @@ impl ToApub for Post {
}
}
type EmbedType = (Option<String>, Option<String>, Option<String>);
Is it possible to do this as a struct?
Its a preference thing, but I really don't like tuple structs, and want to eliminate any others if we have them. You have to guess what that 2nd or 3rd item is, whereas with the regular structs, its a named thing so you know what it is.
Sure I can do that, just added the typedef cause clippy was complaining.
I'm also not too sure why but a lot of the federation tests are failing now. I'll have to inspect.
Found the problem with the tests, I wasnt passing the port when constructing the shared inbox url. Its all green now.