3939#include " cuttlefish/flag_parser/flag.h"
4040#include " cuttlefish/flag_parser/gflags_compat.h"
4141#include " cuttlefish/host/commands/cvd/cli/log_files.h"
42+ #include " cuttlefish/host/commands/cvd/cli/utils.h"
4243#include " cuttlefish/host/commands/cvd/cvd.h"
4344#include " cuttlefish/host/commands/cvd/utils/common.h"
4445#include " cuttlefish/host/commands/cvd/version/version.h"
@@ -200,7 +201,7 @@ std::string ColoredUrl(const std::string& url) {
200201 return output;
201202}
202203
203- void InitializeLogs (std::vector<std::string>& all_args) {
204+ std::optional<std::string> InitializeLogs (std::vector<std::string>& all_args) {
204205 LogSeverity verbosity = CvdVerbosityOption (all_args);
205206 MetadataLevel metadata_level =
206207 isatty (0 ) ? MetadataLevel::ONLY_MESSAGE : MetadataLevel::FULL ;
@@ -215,6 +216,8 @@ void InitializeLogs(std::vector<std::string>& all_args) {
215216 LogToStderrAndFiles (log_files, " " , metadata_level, verbosity);
216217
217218 (void )PruneLogsDirectory (CvdUserLogDir ());
219+
220+ return log_files.empty () ? std::optional<std::string>() : log_files[0 ];
218221}
219222
220223} // namespace
@@ -226,11 +229,17 @@ int main(int argc, char** argv) {
226229
227230 std::vector<std::string> all_args (argv, argv + argc);
228231
229- cuttlefish::InitializeLogs (all_args);
232+ std::optional<std::string> log_file = cuttlefish::InitializeLogs (all_args);
230233
231234 cuttlefish::Result<void > result = cuttlefish::CvdMain (std::move (all_args));
232235 if (result.ok ()) {
233236 return 0 ;
237+ } else if (log_file.has_value ()) {
238+ VLOG (0 ) << result.error ();
239+ cuttlefish::TerminalColors colors (isatty (2 ));
240+ std::cerr << colors.Red () << " 'cvd' encountered an error." << colors.Reset ()
241+ << " Please see '" << colors.Cyan () << *log_file << colors.Reset ()
242+ << " ' for the complete failure report.\n " ;
234243 } else {
235244 // TODO: we should not print the stack trace, instead, we should rely on
236245 // each handler to print the error message directly in the client's
@@ -245,6 +254,6 @@ int main(int argc, char** argv) {
245254 std::cerr << " " << cuttlefish::ColoredUrl (kCuttlefishBugUrl )
246255 << std::endl
247256 << std::endl;
248- return -1 ;
249257 }
258+ return -1 ;
250259}
0 commit comments