Remove usage of Option::unwrap() in activitypub code #80

Merged
dessalines merged 2 commits from apub-remove-unwrap into main 2020-08-11 14:31:09 +00:00
Owner

This removes most usage of Option::unwrap() from activitypub code, and replaces it with context(location_info!())?. If a none value is accessed, it will now throw an error like this:

Error: LemmyError { inner: None value at src/main.rs:63, column 16 }

TODO:

  • replace remaining usages of unwrap() (which are a bit more complicated)
  • maybe replace usages of unwrap() outside of activitypub code
This removes most usage of `Option::unwrap()` from activitypub code, and replaces it with `context(location_info!())?`. If a none value is accessed, it will now throw an error like this: ``` Error: LemmyError { inner: None value at src/main.rs:63, column 16 } ``` TODO: - replace remaining usages of unwrap() (which are a bit more complicated) - maybe replace usages of unwrap() outside of activitypub code
nutomic changed title from WIP: Remove usage of Option::unwrap() in activitypub code to Remove usage of Option::unwrap() in activitypub code 2020-08-10 18:14:51 +00:00
Author
Owner

I 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:

  • make public_key a string field in the db, instead of an option
  • storing shared_inbox_url in CommunityFollowerView

Getting the unwrap was really much easier than I thought.

I 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: - make public_key a string field in the db, instead of an option - storing shared_inbox_url in CommunityFollowerView Getting the unwrap was really much easier than I thought.
dessalines reviewed 2020-08-11 00:16:13 +00:00
@ -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!())?,
Owner

Nice, this is a pretty easy way to do this.

Nice, this is a pretty easy way to do this.
dessalines reviewed 2020-08-11 00:18:03 +00:00
@ -320,0 +317,4 @@
let actor_id = self.actor_id()?;
let url = format!(
"{}://{}{}/inbox",
&actor_id.scheme(),
Owner

Cool, so we do get some url functionality out of this.

Cool, so we do get some url functionality out of this.
Author
Owner

What do you mean get some url functionality?

What do you mean get some url functionality?
dessalines reviewed 2020-08-11 00:23:31 +00:00
@ -147,6 +148,37 @@ impl ToApub for Post {
}
}
type EmbedType = (Option<String>, Option<String>, Option<String>);
Owner

Is it possible to do this as a struct?

struct EmbedType {
  name: Option...
  summary:...
  content:...

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.

Is it possible to do this as a struct? ``` struct EmbedType { name: Option... summary:... content:... ``` 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.
Author
Owner

Sure I can do that, just added the typedef cause clippy was complaining.

Sure I can do that, just added the typedef cause clippy was complaining.
Owner

I'm also not too sure why but a lot of the federation tests are failing now. I'll have to inspect.

I'm also not too sure why but a lot of the federation tests are failing now. I'll have to inspect.
Author
Owner

Found the problem with the tests, I wasnt passing the port when constructing the shared inbox url. Its all green now.

Found the problem with the tests, I wasnt passing the port when constructing the shared inbox url. Its all green now.
nutomic added a new dependency 2020-08-11 14:24:59 +00:00
dessalines merged commit 3da47352be into main 2020-08-11 14:31:09 +00:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Blocks
#81 Remove dead code
LemmyNet/lemmy
Reference: LemmyNet/lemmy#80
No description provided.