Skip to content

Commit

Permalink
[cli][daemon] make multipass delete error message right.
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeliao committed Aug 30, 2024
1 parent bafd3f9 commit 070bf5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/client/cli/cmd/delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ mp::ReturnCode cmd::Delete::run(mp::ArgParser* parser)
return mp::ReturnCode::Ok;
};

auto on_failure = [this](grpc::Status& status) { return standard_failure_handler_for(name(), cerr, status); };
auto on_failure = [this](grpc::Status& status) {

Check warning on line 71 in src/client/cli/cmd/delete.cpp

View check run for this annotation

Codecov / codecov/patch

src/client/cli/cmd/delete.cpp#L71

Added line #L71 was not covered by tests
// grpc::StatusCode::INVALID_ARGUMENT matches mp::VMStateInvalidException
return status.error_code() == grpc::StatusCode::INVALID_ARGUMENT
? standard_failure_handler_for(name(), cerr, status, "Use --purge to forcefully delete it.")
: standard_failure_handler_for(name(), cerr, status);

Check warning on line 75 in src/client/cli/cmd/delete.cpp

View check run for this annotation

Codecov / codecov/patch

src/client/cli/cmd/delete.cpp#L73-L75

Added lines #L73 - L75 were not covered by tests
};

using Client = grpc::ClientReaderWriterInterface<DeleteRequest, DeleteReply>;
auto streaming_callback = [this](const mp::DeleteReply& reply, Client* client) {
Expand Down
12 changes: 7 additions & 5 deletions src/daemon/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,10 @@ try // clang-format on
server->Write(response);
status_promise->set_value(status);
}
catch (const mp::VMStateInvalidException& e)

Check warning on line 2302 in src/daemon/daemon.cpp

View check run for this annotation

Codecov / codecov/patch

src/daemon/daemon.cpp#L2302

Added line #L2302 was not covered by tests
{
status_promise->set_value(grpc::Status{grpc::StatusCode::INVALID_ARGUMENT, e.what()});

Check warning on line 2304 in src/daemon/daemon.cpp

View check run for this annotation

Codecov / codecov/patch

src/daemon/daemon.cpp#L2304

Added line #L2304 was not covered by tests
}
catch (const std::exception& e)
{
status_promise->set_value(grpc::Status(grpc::StatusCode::FAILED_PRECONDITION, e.what(), ""));
Expand Down Expand Up @@ -3080,14 +3084,12 @@ bool mp::Daemon::delete_vm(InstanceTable::iterator vm_it, bool purge, DeleteRepl

mounts[name].clear();

try
// Temporary solution to make multipass delete behave right.
// TODO, move this check into check_state_for_shutdown
if (!(instance->current_state() == VirtualMachine::State::suspended) || purge)
{
instance->shutdown(purge);
}
catch (const VMStateInvalidException& exception)
{
// in the case of VMStateInvalidException, we simply just skip shutdown call
}

if (!purge)
{
Expand Down

0 comments on commit 070bf5f

Please sign in to comment.