softprops / hubcaps

a rust interface for github
http://docs.rs/hubcaps
MIT License
279 stars 68 forks source link

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

Open mre opened 4 years ago

mre commented 4 years ago

🐛 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.