I had previously missed that kafka-protocol provides a ResponseError type for parsing kafka error codes.
This type is super useful, turning the numeric error codes into a meaningful error enum.
So this PR:
Uses ResponseError to parse error codes into meaningful error names before including in shotover errors.
Uses ResponseError to avoid writing error codes as magic numbers
Adds error handling for delegation token creation responses which was previously entirely missing (in scram_over_mtls.rs)
PR Walkthrough notes
Some notes on rust features for newstarters reviewing this PR.
Option
rust has a core type in the standard library called Option.
It is an enum defined as:
enum Option<T> {
Some(T),
None
}
It is similar to java's Optional but a lot better.
In other languages you may set a variable to null to say that no value exists for that variable.
However no such functionality exists in rust.
Instead we wrap the value in Option to allow for the case where the value does not exist.
For example:
fn print_value(value: Option<i32>) {
if let Some(value) = value {
println!("the value is {value}");
}
}
print_value(Some(10)); // prints: the value is 10
print_value(None); // does not print anything
And this is equivalent:
fn print_value(value: Option<i32>) {
match value {
Some(value) => println!("the value is {value}");
None => {}
}
}
print_value(Some(10)); // prints: the value is 10
print_value(None); // does not print anything
Result
rust has a core type in the standard library called Option.
It is an enum defined as:
enum Result<T, E> {
Ok(T),
Err(E)
}
Some languages use exceptions for error handling.
Rust does not have exceptions.
Some languages use function return values for error handling.
Rust does do this, but almost always through the Result type.
I had previously missed that kafka-protocol provides a ResponseError type for parsing kafka error codes. This type is super useful, turning the numeric error codes into a meaningful error enum. So this PR:
ResponseError
to parse error codes into meaningful error names before including in shotover errors.ResponseError
to avoid writing error codes as magic numbersPR Walkthrough notes
Some notes on rust features for newstarters reviewing this PR.
Option
rust has a core type in the standard library called Option. It is an enum defined as:
It is similar to java's Optional but a lot better.
In other languages you may set a variable to
null
to say that no value exists for that variable. However no such functionality exists in rust. Instead we wrap the value inOption
to allow for the case where the value does not exist.For example:
And this is equivalent:
Result
rust has a core type in the standard library called Option. It is an enum defined as:
Some languages use exceptions for error handling. Rust does not have exceptions. Some languages use function return values for error handling. Rust does do this, but almost always through the
Result
type.anyhow errors