Skip to content

Commit

Permalink
Return clear message when no groups exist
Browse files Browse the repository at this point in the history
A clear message existed for stop and status, it's extended for:
- bugreport
- remove
- display
- start
  • Loading branch information
jemoreira committed Sep 20, 2024
1 parent 3f9b026 commit 2815bd5
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Result<cvd::Response> CvdBugreportCommandHandler::Handle(
std::string android_host_out;
std::string home = CF_EXPECT(SystemWideUserHome());
if (!CF_EXPECT(IsHelpSubcmd(cmd_args))) {
if (!CF_EXPECT(instance_manager_.HasInstanceGroups())) {
return NoGroupResponse(request);
}
auto instance_group = CF_EXPECT(SelectGroup(instance_manager_, request));
android_host_out = instance_group.HostArtifactsPath();
home = instance_group.HomeDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <string>
#include <vector>

#include "common/libs/fs/shared_buf.h"
#include "common/libs/utils/contains.h"
#include "common/libs/utils/subprocess.h"
#include "common/libs/utils/users.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <string>
#include <vector>

#include "common/libs/fs/shared_buf.h"
#include "common/libs/utils/contains.h"
#include "common/libs/utils/result.h"
#include "host/commands/cvd/group_selector.h"
Expand Down Expand Up @@ -78,6 +77,9 @@ class RemoveCvdCommandHandler : public CvdServerHandler {
return Success();
}

if (!CF_EXPECT(instance_manager_.HasInstanceGroups())) {
return NoGroupResponse(request);
}
auto group = CF_EXPECT(SelectGroup(instance_manager_, request));

auto stop_res = StopGroup(group, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ Result<cvd::Response> CvdStartCommandHandler::Handle(
return ResponseFromSiginfo(infop);
}

if (!CF_EXPECT(instance_manager_.HasInstanceGroups())) {
return NoGroupResponse(request);
}

CF_EXPECT(ConsumeDaemonModeFlag(subcmd_args));
subcmd_args.push_back("--daemon=true");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Result<cvd::Response> CvdStatusCommandHandler::Handle(
const bool has_print = CF_EXPECT(HasPrint(cmd_args));

if (!CF_EXPECT(instance_manager_.HasInstanceGroups())) {
return CF_EXPECT(NoGroupResponse(request));
return NoGroupResponse(request);
}
RequestWithStdio new_request = CF_EXPECT(ProcessInstanceNameFlag(request));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Result<cvd::Response> CvdStopCommandHandler::Handle(
}

if (!CF_EXPECT(instance_manager_.HasInstanceGroups())) {
return CF_EXPECT(NoGroupResponse(request));
return NoGroupResponse(request);
}
cvd_common::Envs envs = request.Envs();
const auto selector_args = request.SelectorArgs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ std::string_view TerminalColors::Cyan() const {
return is_tty_ ? kTerminalCyan : "";
}

Result<cvd::Response> NoGroupResponse(const RequestWithStdio& request) {
cvd::Response NoGroupResponse(const RequestWithStdio& request) {
cvd::Response response;
response.mutable_command_response();
response.mutable_status()->set_code(cvd::Status::OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Result<bool> IsHelpSubcmd(const std::vector<std::string>& args);

// Call this when there is no instance group is running
// The function does not verify that.
Result<cvd::Response> NoGroupResponse(const RequestWithStdio& request);
cvd::Response NoGroupResponse(const RequestWithStdio& request);

// Call this when there is more than one group, which the selector flags are
// not sufficients to choose one from. The function does not verify that.
Expand Down

0 comments on commit 2815bd5

Please sign in to comment.