this post was submitted on 09 Jul 2023
9 points (100.0% liked)

Rust Lang

3 readers
1 users here now

Rules [Developing]

Observe our code of conduct

Constructive criticism only

No endless relitigation

No low-effort content

No memes or image macros

No NSFW Content

founded 1 year ago
MODERATORS
 

I don't know Rust, but trying to hack on Lemmy 0.18.1 enough to get a better error message out.

error: data did not match any variant of untagged enum AnnouncableActivities

where: crates/apub/src/activities/community/announce.rs, line: 46

https://github.com/LemmyNet/lemmy/blob/0c82f4e66065b5772fede010a879d327135dbb1e/crates/apub/src/activities/community/announce.rs#L46

That seems to be the function parameters themselves?

Is the error caused by RawAnnouncableActivities not matching the enum AnnouncableActivities and the try_into?

  warn!("zebratrace receive {:?}", self);

Works for adding logging, but I'd like the code to log self only when the enum does not match (errors). Thank you.

top 6 comments
sorted by: hot top controversial new old
[–] colonial@lemmy.world 5 points 1 year ago (2 children)

Your analysis sounds correct - data did not match any variant of untagged enum is definitely from serde IIRC - but I can't say for certain just by looking at the code.

but I’d like the code to log self only when the enum does not match (errors). Thank you.

Try changing line 48 to this:

let object = match self.clone().try_into::<AnnouncableActivities>() {
    Ok(object) => object,
    Err(e) => {
        warn!("zebratrace receive {:?}", self);
        return Err(e);
    }
}

(This probably isn't the best way to do this, but it's what I came up with off the top of my head :P)

[–] anlumo@feddit.de 2 points 1 year ago

Serde handles untagged enums in the way that it tries to deserialize every variant of that enum from top to bottom with the given data, and returns the first one that doesn’t throw an error. The error indicates that all of them threw an error when trying to deserialize the data.

[–] RoundSparrow@lemmy.ml 1 points 1 year ago (1 children)

let object = match self.clone().try_into::() { Ok(object) => object, Err(e) => { warn!("zebratrace receive {:?}", self); return Err(e); } }

Compiler didn't like your code:

let object = match self.clone().try_into::<AnnouncableActivities>() {
   |                                     ^^^^^^^^ expected 0 generic arguments
   |
help: consider moving this generic argument to the `TryInto` trait, which takes up to 1 argument
   |
52 |     let object = match TryInto::<AnnouncableActivities>::try_into(self.clone()) {
   |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: remove these generics
   |
52 -     let object = match self.clone().try_into::<AnnouncableActivities>() {
52 +     let object = match self.clone().try_into() {

[–] colonial@lemmy.world 5 points 1 year ago (1 children)

Yeah, I thought I was botching something important.

This should work:

let object: AnnouncableActivities = match self.clone().try_into() {
[–] RoundSparrow@lemmy.ml 2 points 1 year ago (1 children)

Ok, that code worked, thank you.

[–] colonial@lemmy.world 6 points 1 year ago

No problem! Don't be afraid to ask if you've got any other questions :D