From d1cd5f7ad687b752c94b1a4f2f2d893eb429df8e Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Tue, 18 Jun 2024 03:44:31 +0800 Subject: [PATCH] cabana: improved error messaging (#32768) * check user authenrication * Update tools/cabana/streams/replaystream.cc --------- Co-authored-by: Adeeb Shihadeh old-commit-hash: 54da59c1feb917896538ce8aa22bf4f12af20824 --- tools/cabana/streams/replaystream.cc | 27 +++++++++++++++++++++++---- tools/replay/replay.h | 1 + tools/replay/route.cc | 3 +++ tools/replay/route.h | 10 ++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/tools/cabana/streams/replaystream.cc b/tools/cabana/streams/replaystream.cc index 5d4925a67a..bdb9ebb014 100644 --- a/tools/cabana/streams/replaystream.cc +++ b/tools/cabana/streams/replaystream.cc @@ -56,7 +56,28 @@ bool ReplayStream::loadRoute(const QString &route, const QString &data_dir, uint QObject::connect(replay.get(), &Replay::seeking, this, &AbstractStream::seeking); QObject::connect(replay.get(), &Replay::seekedTo, this, &AbstractStream::seekedTo); QObject::connect(replay.get(), &Replay::segmentsMerged, this, &ReplayStream::mergeSegments); - return replay->load(); + bool success = replay->load(); + if (!success) { + if (replay->lastRouteError() == RouteLoadError::AccessDenied) { + auto auth_content = util::read_file(util::getenv("HOME") + "/.comma/auth.json"); + QString message; + if (auth_content.empty()) { + message = "Authentication Required. Please run the following command to authenticate:\n\n" + "python tools/lib/auth.py\n\n" + "This will grant access to routes from your comma account."; + } else { + message = tr("Access Denied. You do not have permission to access route:\n\n%1\n\n" + "This is likely a private route.").arg(route); + } + QMessageBox::warning(nullptr, tr("Access Denied"), message); + } else if (replay->lastRouteError() == RouteLoadError::NetworkError) { + QMessageBox::warning(nullptr, tr("Network Error"), + tr("Unable to load the route:\n\n %1.\n\nPlease check your network connection and try again.").arg(route)); + } else { + QMessageBox::warning(nullptr, tr("Route Load Failed"), tr("Failed to load route: '%1'").arg(route)); + } + } + return success; } void ReplayStream::start() { @@ -144,7 +165,7 @@ OpenReplayWidget::OpenReplayWidget(AbstractStream **stream) : AbstractOpenStream bool OpenReplayWidget::open() { QString route = route_edit->text(); QString data_dir; - if (int idx = route.lastIndexOf('/'); idx != -1) { + if (int idx = route.lastIndexOf('/'); idx != -1 && util::file_exists(route.toStdString())) { data_dir = route.mid(0, idx + 1); route = route.mid(idx + 1); } @@ -161,8 +182,6 @@ bool OpenReplayWidget::open() { if (replay_stream->loadRoute(route, data_dir, flags)) { *stream = replay_stream.release(); - } else { - QMessageBox::warning(nullptr, tr("Warning"), tr("Failed to load route: '%1'").arg(route)); } } return *stream != nullptr; diff --git a/tools/replay/replay.h b/tools/replay/replay.h index 8b51ab054d..7e1815ede0 100644 --- a/tools/replay/replay.h +++ b/tools/replay/replay.h @@ -53,6 +53,7 @@ public: uint32_t flags = REPLAY_FLAG_NONE, QString data_dir = "", QObject *parent = 0); ~Replay(); bool load(); + RouteLoadError lastRouteError() const { return route_->lastError(); } void start(int seconds = 0); void stop(); void pause(bool pause); diff --git a/tools/replay/route.cc b/tools/replay/route.cc index e8e73459ea..18c962abd5 100644 --- a/tools/replay/route.cc +++ b/tools/replay/route.cc @@ -74,7 +74,10 @@ bool Route::loadFromServer(int retries) { return loadFromJson(result); } else if (err == QNetworkReply::ContentAccessDenied || err == QNetworkReply::AuthenticationRequiredError) { rWarning(">> Unauthorized. Authenticate with tools/lib/auth.py <<"); + err_ = RouteLoadError::AccessDenied; return false; + } else { + err_ = RouteLoadError::NetworkError; } rWarning("Retrying %d/%d", i, retries); util::sleep_for(3000); diff --git a/tools/replay/route.h b/tools/replay/route.h index f956497804..acc73d509a 100644 --- a/tools/replay/route.h +++ b/tools/replay/route.h @@ -12,6 +12,14 @@ #include "tools/replay/logreader.h" #include "tools/replay/util.h" +enum class RouteLoadError { + None, + AccessDenied, + NetworkError, + FileNotFound, + UnknownError +}; + struct RouteIdentifier { QString dongle_id; QString timestamp; @@ -33,6 +41,7 @@ class Route { public: Route(const QString &route, const QString &data_dir = {}); bool load(); + RouteLoadError lastError() const { return err_; } inline const QString &name() const { return route_.str; } inline const QDateTime datetime() const { return date_time_; } inline const QString &dir() const { return data_dir_; } @@ -50,6 +59,7 @@ protected: QString data_dir_; std::map segments_; QDateTime date_time_; + RouteLoadError err_ = RouteLoadError::None; }; class Segment : public QObject {