Skip to content

Commit

Permalink
[daemon][cli] changed to grpc::StatusCode::FAILED_PRECONDITION instea…
Browse files Browse the repository at this point in the history
…d of INVALID_ARGUMENT to avoid unwanted matches.
  • Loading branch information
georgeliao committed Sep 2, 2024
1 parent 23cdac3 commit fc103db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/client/cli/cmd/delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ mp::ReturnCode cmd::Delete::run(mp::ArgParser* parser)
};

auto on_failure = [this](grpc::Status& status) {
// grpc::StatusCode::INVALID_ARGUMENT matches mp::VMStateInvalidException
return status.error_code() == grpc::StatusCode::INVALID_ARGUMENT
// grpc::StatusCode::FAILED_PRECONDITION matches mp::VMStateInvalidException
return status.error_code() == grpc::StatusCode::FAILED_PRECONDITION
? standard_failure_handler_for(name(), cerr, status, "Use --purge to forcefully delete it.")
: standard_failure_handler_for(name(), cerr, status);
};
Expand Down
4 changes: 2 additions & 2 deletions src/client/cli/cmd/stop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ mp::ReturnCode cmd::Stop::run(mp::ArgParser* parser)
auto on_failure = [this, &spinner](grpc::Status& status) {
spinner.stop();

// grpc::StatusCode::INVALID_ARGUMENT matches mp::VMStateInvalidException
return status.error_code() == grpc::StatusCode::INVALID_ARGUMENT
// grpc::StatusCode::FAILED_PRECONDITION matches mp::VMStateInvalidException
return status.error_code() == grpc::StatusCode::FAILED_PRECONDITION
? standard_failure_handler_for(name(), cerr, status, "Use --force to power it off.")
: standard_failure_handler_for(name(), cerr, status);
};
Expand Down
8 changes: 4 additions & 4 deletions src/daemon/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,11 +2148,11 @@ try // clang-format on
}
catch (const mp::VMStateInvalidException& e)
{
status_promise->set_value(grpc::Status{grpc::StatusCode::INVALID_ARGUMENT, e.what()});
status_promise->set_value(grpc::Status{grpc::StatusCode::FAILED_PRECONDITION, e.what()});
}
catch (const std::exception& e)
{
status_promise->set_value(grpc::Status(grpc::StatusCode::FAILED_PRECONDITION, e.what(), ""));
status_promise->set_value(grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
}

void mp::Daemon::suspend(const SuspendRequest* request,
Expand Down Expand Up @@ -2301,11 +2301,11 @@ try // clang-format on
}
catch (const mp::VMStateInvalidException& e)
{
status_promise->set_value(grpc::Status{grpc::StatusCode::INVALID_ARGUMENT, e.what()});
status_promise->set_value(grpc::Status{grpc::StatusCode::FAILED_PRECONDITION, e.what()});
}
catch (const std::exception& e)
{
status_promise->set_value(grpc::Status(grpc::StatusCode::FAILED_PRECONDITION, e.what(), ""));
status_promise->set_value(grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
}

void mp::Daemon::umount(const UmountRequest* request,
Expand Down

0 comments on commit fc103db

Please sign in to comment.