Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for full torrent file deserialization #32

Closed
wants to merge 2 commits into from
Closed

Add test for full torrent file deserialization #32

wants to merge 2 commits into from

Conversation

josecelano
Copy link
Collaborator

I'm using this library to deserialize a torrent file like in this repo example.

For some reason I do not know yet, it's not working with some torrents when I use the library in my project, but it's not a library issue because it's working as you can see in this PR.

This is the bug I'm trying to fix:

torrust/torrust-index#266

I've added a test for full torrent deserialization, which, I suppose, it's the most common use for this package. I have included the torrents I have problems with.

FYI, one test is failing:

---- ser_de_flattened_adjacently_tagged_enum stdout ----
bytes: "d7:contentd5:tokeni456ee2:idi123e4:type7:Requeste"
thread 'ser_de_flattened_adjacently_tagged_enum' panicked at tests/tests.rs:39:41:
called `Result::unwrap()` on an `Err` value: InvalidType("Invalid Type: byte array (expected: `string or map`)")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@josecelano josecelano marked this pull request as ready for review September 15, 2023 13:30
@josecelano
Copy link
Collaborator Author

I was able to reproduce the bug with a test:

$ cargo test deserialize_full_torrent_files
    Finished test [unoptimized + debuginfo] target(s) in 0.00s
     Running unittests src/lib.rs (target/debug/deps/serde_bencode-ce78c065639cd56b)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/tests.rs (target/debug/deps/tests-6f3d7857ebd77de3)

running 1 test
test deserialize_full_torrent_files ... FAILED

failures:

---- deserialize_full_torrent_files stdout ----
Parsing torrent file: "./tests/fixtures/torrents/006-VictorYerena.txt-51f0aef3527d73ee84a0b031df648b349a01bd47.torrent"
thread 'deserialize_full_torrent_files' panicked at tests/tests.rs:558:21:
ERROR: Invalid Type: sequence (expected: `bytes`)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    deserialize_full_torrent_files

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 40 filtered out; finished in 0.00s

error: test failed, to rerun pass `--test tests`

@josecelano
Copy link
Collaborator Author

This is the line throwing the error:

Error::InvalidType(format!("Invalid Type: {} (expected: `{}`)", unexp, exp))

    fn invalid_type(unexp: Unexpected, exp: &dyn Expected) -> Self {
        Error::InvalidType(format!("Invalid Type: {} (expected: `{}`)", unexp, exp))
    }

And it seems the problem is there is no implementation for this function:

https://github.com/serde-rs/serde/blob/master/serde/src/de/mod.rs#L1641-L1647

    /// The input contains a sequence of elements.
    ///
    /// The default implementation fails with a type error.
    fn visit_seq<A>(self, seq: A) -> Result<Self::Value, A::Error>
    where
        A: SeqAccess<'de>,
    {
        let _ = seq;
        Err(Error::invalid_type(Unexpected::Seq, &self))
    }

@josecelano
Copy link
Collaborator Author

Do you happen to know if this repo is actively maintained? cc @toby @chpio

@josecelano josecelano closed this by deleting the head repository Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant