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

The PrInfo struct is being populated directly from the JSON response without any error checking. If the response does not contain the expected fields, this could cause a panic. Consider adding error handling to ensure that the expected fields are present in the response. #55

Open
avikalpg opened this issue Oct 31, 2023 · 1 comment

Comments

@avikalpg
Copy link
Member

          The `PrInfo` struct is being populated directly from the JSON response without any error checking. If the response does not contain the expected fields, this could cause a panic. Consider adding error handling to ensure that the expected fields are present in the response.
let pr_info = match (pr_data["destination"]["commit"]["hash"].as_str(), pr_data["source"]["commit"]["hash"].as_str(), pr_data["state"].as_str(), pr_data["source"]["branch"]["name"].as_str()) {
    (Some(base_head_commit), Some(pr_head_commit), Some(state), Some(pr_branch)) => PrInfo {
        base_head_commit: base_head_commit.to_string(),
        pr_head_commit: pr_head_commit.to_string(),
        state: state.to_string(),
        pr_branch: pr_branch.to_string(),
    },
    _ => {
        eprintln!("Failed to parse PR data: {:?}", pr_data);
        return None;
    }
};

Originally posted by @coderabbitai[bot] in #46 (comment)

@avikalpg
Copy link
Member Author

@tapishr I think we should do this here. Muskan said that you had some reservations about using the match function - hence I am not doing this right away. But I understand the point that we just assuming that these fields will be present in the response from Bitbucket and will be correctly passed in the pubsub message.

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

No branches or pull requests

1 participant