-
Notifications
You must be signed in to change notification settings - Fork 71
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
[Question] Recommended way to handle errors? #537
Comments
I see this on the best practices page:
So, I suppose I'm largely asking what the right way to properly handle errors is. For example, in my particular case, my load test is just like #[tokio::main]
async fn main() -> Result<(), GooseError> {
GooseAttack::initialize()?
// In this example, we only create a single scenario, named "WebsiteUser".
.register_scenario(
scenario!("WebsiteUser")
// This transaction only runs one time when the user first starts.
.register_transaction(transaction!(website_signup).set_on_start())
.register_transaction(transaction!(authenticated_index)),
)
.execute()
.await?;
Ok(())
} Where authenticated_index might panic if it is using |
I'd like |
Fully agreed, would be good to be able to set custom errors before sending a request. I'm doing some terrible things as workaround: // Send request to job details page, the URL was parsed in the previous request.
async fn job_detail(user: &mut GooseUser) -> TransactionResult {
// We can't set custom errors and return before sending a request with
// Goose, so just set an invalid path.
let mut job_detail_url = "%%invalid".to_string();
if let Some(session) = user.get_session_data::<Session>() {
if let Some(url) = &session.job_detail_url {
job_detail_url = url.clone();
}
};
send_request_and_validate(user, &job_detail_url, "Teilen").await?;
Ok(())
} Much better would be to return some kind of user error: // Send request to job details page, the URL was parsed in the previous request.
async fn job_detail(user: &mut GooseUser) -> TransactionResult {
if let Some(session) = user.get_session_data::<Session>() {
if let Some(url) = &session.job_detail_url {
return send_request_and_validate(user, &job_detail_url, "Teilen").await;
}
};
Err(TransactionError::User("Job detail page URL missing in session".to_string()))
} Or similar. |
Adding refernce to #250 which I believe has related discussion |
I'm working on a load test, and am wondering what the right way to handle errors is. For example, suppose I have a load test which logs in to a service to get a JWT, and sets that in the session. Then, the next transactions use
.get_session_data()
.If I use get_session_data_unchecked, I'll see panics like
So, I'd like to handle the error more gracefully. I assume the root cause here is that the service I am load-testing timed-out on the initial log-in transaction, thus failing to set the session data.
However, the transaction functions all return a
TransactionResult
, and theTransactionError
they box seem quite specific: https://docs.rs/goose/latest/goose/goose/enum.TransactionError.htmlIs there an example of how to use the non-panicing
get_session_data
and bubble up the error, or otherwise handle it gracefully?Should I just return
Ok(())
immediately, skipping the following requests, which require the JWT? Will doing so result in one of my GooseUsers running a scenario's transactions over and over that don't actually do anything?The text was updated successfully, but these errors were encountered: