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

Return useful error when encountering unknown kafka API key #1477

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions shotover/src/frame/kafka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,13 @@ impl KafkaFrame {
fn parse_request(mut bytes: Bytes) -> Result<Self> {
let api_key = i16::from_be_bytes(bytes[0..2].try_into().unwrap());
let api_version = i16::from_be_bytes(bytes[2..4].try_into().unwrap());
let header_version = ApiKey::try_from(api_key)
.unwrap()
.request_header_version(api_version);
let api_key =
ApiKey::try_from(api_key).map_err(|_| anyhow!("unknown api key {api_key}"))?;

let header_version = api_key.request_header_version(api_version);
let header = RequestHeader::decode(&mut bytes, header_version)
.context("Failed to decode request header")?;

let api_key = ApiKey::try_from(header.request_api_key)
.map_err(|_| anyhow!("unknown api key {}", header.request_api_key))?;
let version = header.request_api_version;
let body = match api_key {
ApiKey::ProduceKey => RequestBody::Produce(decode(&mut bytes, version)?),
Expand Down
Loading