-
I'm very new to Rust and am having a bit of trouble with error processing. I'm trying to write event data to CloudWatchLogs and one of the first things to do is create a log stream. This code will create the log stream without problems if it doesn't already exist. match client
.create_log_stream()
.log_group_name("/my/group/name")
.log_stream_name("my_test_stream")
.send()
.await
{
Ok(_) => println!("Created new log stream."),
Err(e) => match e {
Error => println!("Log stream already exists"),
_ => panic!("Error creating log stream: {}", e),
}
} If the log stream exists I get a I guess my question is, how do you match on a particular Error? Am I missing a module somewhere or something? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Errors in the Rust SDKs have a With this in mind, your code could look like this: match client
.create_log_stream()
.log_group_name("/my/group/name")
.log_stream_name("my_test_stream")
.send()
.await
{
Ok(_) => println!("Created new log stream."),
Err(e) => {
if e.is_resource_already_exists_exception() { println!("Log stream already exists") }
else { panic!("Error creating log stream: {}", e) };
}
} |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Errors in the Rust SDKs have a
kind
field that contains this information and we provide methods for checking this. Here's the docs forCreateLogStreamError
.With this in mind, your code could look like this: