Skip to content

Commit cf0d080

Browse files
committed
Make suggestions to the user when fetching fails
Specifically, trying to make typos and unauthenticated errors more obvious to users beyond the API error response stating that the build was not found. Test: relocate `.acloud_oauth2.dat` file Test: attempt to fetch an internal branch with no credential flags Bug: 427744621
1 parent 27c6569 commit cf0d080

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

base/cvd/cuttlefish/host/libs/web/android_build_api.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,28 @@ Result<std::string> AndroidBuildApi::BuildStatus(const DeviceBuild& build) {
227227
android_build_url_->GetBuildStatusUrl(build.id, build.target);
228228
auto response =
229229
CF_EXPECT(HttpGetToJson(http_client, url, CF_EXPECT(Headers())));
230-
const Json::Value json = CF_EXPECT(GetResponseJson(response),
231-
"Error fetching build status for build:\n"
232-
<< build);
230+
231+
std::string no_auth_error_message;
232+
if (credential_source == nullptr && response.http_code == 404) {
233+
// In LatestBuildId we currently cannot distinguish between the cases:
234+
// - user provided a build ID (not an error)
235+
// - user provided a branch with a typo
236+
// - user provided a branch without the necessary authentication
237+
// (for example, internal branches)
238+
// This message is a best attempt at helping the user in third case
239+
no_auth_error_message =
240+
"\n\nThis fetch was run unauthenticated, which could be the "
241+
"problem.\nTry `cvd help login`";
242+
}
243+
const Json::Value json = CF_EXPECT(
244+
GetResponseJson(response),
245+
"Error fetching build status for build:\n"
246+
<< build
247+
<< "\n\nIf you specified a branch and it appears in the build id "
248+
"field of this error, there was a problem retrieving the latest "
249+
"build id.\n\nIs there a typo in the branch or target name?"
250+
<< no_auth_error_message);
251+
233252
return CF_EXPECT(GetValue<std::string>(json, { "buildAttemptStatus" }));
234253
}
235254

0 commit comments

Comments
 (0)