Skip to content

Commit

Permalink
Return useful error when encountering unknown kafka API key (#1477)
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai authored Feb 14, 2024
1 parent 5443175 commit f846d40
Showing 1 changed file with 4 additions and 5 deletions.
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

0 comments on commit f846d40

Please sign in to comment.