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

serde error: invalid type: null, expected struct User #268

Open
mre opened this issue Sep 2, 2020 · 0 comments
Open

serde error: invalid type: null, expected struct User #268

mre opened this issue Sep 2, 2020 · 0 comments
Labels

Comments

@mre
Copy link
Contributor

mre commented Sep 2, 2020

🐛 Bug description

Some Github repo commits don't have a valid author.
Example: curl https://api.github.com/repos/TNG/ArchUnit/commits/c395bc282b6c52feb0165a1657086d711547829f.

In this case, the API returns null for the author field.
This cannot be deserialized properly into a User struct by serde.
As a result, we're getting errors when using hubcaps to read a list of commits over here:

Error: Codec(Error("invalid type: null, expected struct User", line: 1, column: 67983))

(See the example code below to reproduce.)

🤔 Expected Behavior

hubcaps should not throw an error or this edge-case should be documented with a workaround.
I was also thinking that the author field might be optional and be None in case of null, but that would be a breaking change and it would make the normal flow a bit more cumbersome.

👟 Steps to reproduce

use hubcaps::{Credentials, Github, Result};
use std::env;

#[tokio::main]
async fn main() -> Result<()> {
    let github = Github::new(
      String::from("user-agent-name"),
      env::var("GITHUB_TOKEN").ok().map(Credentials::Token),
    )?;

    github
        .repo("tng", "archunit")
        .commits()
        .get("c395bc282b6c52feb0165a1657086d711547829f")
        .await?;
    Ok(())
}

🌍 Your environment

hubcaps version: 0.6.1
tokio: 0.2

Credits

@AristoChen for finding the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant