Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Log why saved UI data is unavailable

Leonardo Lobato5cfc2b6aaa60
diff --git a/src/app/persistence_controller.cpp b/src/app/persistence_controller.cpp
index 58d1e0c..6790204 100644
--- a/src/app/persistence_controller.cpp
+++ b/src/app/persistence_controller.cpp
@@ -13,6 +13,27 @@ bool PreferencesLoadFailed(PreferencesLoadStatus status) {
status == PreferencesLoadStatus::kDefaultReadError;
}
+const char* ErrorName(StorageError error) {
+ switch (error) {
+ case StorageError::kNone: return "none";
+ case StorageError::kInvalidPath: return "invalid path";
+ case StorageError::kNotFound: return "not found";
+ case StorageError::kOpenFailed: return "open failed";
+ case StorageError::kReadFailed: return "read failed";
+ case StorageError::kWriteFailed: return "write failed";
+ case StorageError::kRenameFailed: return "rename failed";
+ case StorageError::kInvalidData: return "invalid data";
+ case StorageError::kPermissionFailed: return "permission failed";
+ case StorageError::kRemoveFailed: return "remove failed";
+ case StorageError::kSyncFailed: return "sync failed";
+ }
+ return "unknown";
+}
+
+std::string Failure(StorageError error, const std::string& message) {
+ return message.empty() ? ErrorName(error) : std::string(ErrorName(error)) + ": " + message;
+}
+
PreferencesLoadResult PreferenceResult(const PersistenceEvent& event) {
PreferencesLoadResult result;
if (event.preferences) result.preferences = *event.preferences;
@@ -40,6 +61,7 @@ void PersistenceController::BeginPreferencesLoad() {
failure.diagnostic = "Preferences are busy and could not be loaded.";
model_.ApplyPreferences(preferences_load_token_, failure);
preferences_load_failed_ = true;
+ Report(kPreferencesLoad, failure.diagnostic);
}
void PersistenceController::BeginOrganizationLoad() {
@@ -52,6 +74,7 @@ void PersistenceController::BeginOrganizationLoad() {
model_.FailOrganizationLoad(kDeviceOrganization, organization_load_token_,
StorageError::kReadFailed);
organization_load_failed_ = true;
+ Report(kOrganizationLoad, "busy");
}
// Organization belongs to the device: store accounts coming and going leave it alone.
@@ -101,10 +124,12 @@ void PersistenceController::Apply(PersistenceEvent event) {
preferences_load_request_ = 0;
const auto loaded = PreferenceResult(event);
preferences_load_failed_ = PreferencesLoadFailed(loaded.status);
+ Report(kPreferencesLoad, preferences_load_failed_ ? Failure(event.error, event.message) : std::string());
model_.ApplyPreferences(preferences_load_token_, loaded);
return;
}
if (event.kind == PersistenceEventKind::kPreferencesSaved) {
+ Report(kPreferencesSave, event.error == StorageError::kNone ? std::string() : Failure(event.error, event.message));
model_.PreferencesSaveResult(event.revision, event.error);
return;
}
@@ -117,15 +142,30 @@ void PersistenceController::Apply(PersistenceEvent event) {
if (event.error == StorageError::kNone) {
organization_load_failed_ = !model_.ApplyOrganization(
kDeviceOrganization, organization_load_token_, std::move(event.organization));
+ // Read fine, but holds more than the Library can show.
+ Report(kOrganizationLoad, organization_load_failed_ ? "too large for the Library" : "");
} else {
organization_load_failed_ = true;
+ Report(kOrganizationLoad, Failure(event.error, event.message));
model_.FailOrganizationLoad(kDeviceOrganization, organization_load_token_,
event.error);
}
return;
}
- if (event.kind == PersistenceEventKind::kOrganizationSaved)
+ if (event.kind == PersistenceEventKind::kOrganizationSaved) {
+ Report(kOrganizationSave, event.error == StorageError::kNone ? std::string() : Failure(event.error, event.message));
model_.OrganizationSaveResult(event.account_id, event.revision, event.error);
+ }
+}
+
+void PersistenceController::Report(Channel channel, const std::string& failure) {
+ static const char* const kNames[kChannels] = {"preferences load", "preferences save", "organization load",
+ "organization save"};
+ auto& last = reported_[channel];
+ if (failure == last) return;
+ if (log_) log_(failure.empty() ? std::string(kNames[channel]) + " works again"
+ : std::string(kNames[channel]) + " failed: " + failure);
+ last = failure;
}
void PersistenceController::ObserveAndSave() {
diff --git a/src/app/persistence_controller.h b/src/app/persistence_controller.h
index 34770b0..ace1594 100644
--- a/src/app/persistence_controller.h
+++ b/src/app/persistence_controller.h
@@ -5,7 +5,9 @@
#include <cstddef>
#include <cstdint>
+#include <functional>
#include <optional>
+#include <string>
namespace playden::app {
@@ -34,12 +36,19 @@ class PersistenceController {
// drains accepted saves before stopping the worker.
void FlushAndShutdown();
+ // Receives one line when preferences or organization fail to load or save, and one when they work again
+ // ("Saved UI data is unavailable" says nothing else). A repeat of the same failure is not logged again.
+ void SetLog(std::function<void(const std::string&)> log) { log_ = std::move(log); }
+
private:
void Pump(std::size_t maximum);
void ObserveAndSave();
void BeginPreferencesLoad();
void BeginOrganizationLoad();
void Apply(PersistenceEvent);
+ enum Channel { kPreferencesLoad, kPreferencesSave, kOrganizationLoad, kOrganizationSave, kChannels };
+ // failure: empty when the channel worked.
+ void Report(Channel channel, const std::string& failure);
homebrew::Simulation& model_;
PersistenceService& service_;
@@ -55,6 +64,8 @@ class PersistenceController {
bool preferences_load_failed_ = false;
bool organization_load_failed_ = false;
bool shutting_down_ = false;
+ std::function<void(const std::string&)> log_;
+ std::string reported_[kChannels]; // the last failure logged per channel; empty once it worked again
};
} // namespace playden::app
diff --git a/src/app/persistence_service.cpp b/src/app/persistence_service.cpp
index 5bb8a77..c270f88 100644
--- a/src/app/persistence_service.cpp
+++ b/src/app/persistence_service.cpp
@@ -255,6 +255,7 @@ void PersistenceService::Run() {
event.account_generation = failed.generation;
event.revision = failed.revision;
event.error = StorageError::kInvalidData;
+ event.message = "unexpected exception";
if (failed.command == Command::kLoadPreferences)
event.kind = PersistenceEventKind::kPreferencesLoaded;
else if (failed.command == Command::kSavePreferences)
@@ -297,6 +298,7 @@ void PersistenceService::Execute(Job job) {
event.preferences_status = loaded.status;
event.error = PreferenceLoadError(loaded.status);
event.preferences = loaded.preferences;
+ event.message = loaded.diagnostic;
std::lock_guard<std::mutex> lock(mutex_);
if (!stopping_) PushEvent(std::move(event));
return;
@@ -305,6 +307,7 @@ void PersistenceService::Execute(Job job) {
const auto saved = preferences_.Save(job.preferences);
event.kind = PersistenceEventKind::kPreferencesSaved;
event.error = saved.ok() ? StorageError::kNone : saved.error();
+ if (!saved.ok()) event.message = saved.message();
std::lock_guard<std::mutex> lock(mutex_);
PushEvent(std::move(event));
return;
@@ -314,6 +317,7 @@ void PersistenceService::Execute(Job job) {
event.kind = PersistenceEventKind::kOrganizationLoaded;
event.error = loaded.ok() ? StorageError::kNone : loaded.error();
if (loaded.ok()) event.organization = loaded.value();
+ else event.message = loaded.message();
std::lock_guard<std::mutex> lock(mutex_);
if (!stopping_ && job.account == organization_account_ &&
job.generation == organization_generation_) PushEvent(std::move(event));
@@ -323,6 +327,7 @@ void PersistenceService::Execute(Job job) {
const auto saved = organizations_.Save(job.account, job.organization);
event.kind = PersistenceEventKind::kOrganizationSaved;
event.error = saved.ok() ? StorageError::kNone : saved.error();
+ if (!saved.ok()) event.message = saved.message();
std::lock_guard<std::mutex> lock(mutex_);
if (job.account == organization_account_ &&
job.generation == organization_generation_) PushEvent(std::move(event));
diff --git a/src/app/persistence_service.h b/src/app/persistence_service.h
index 2a0bbdf..4882f53 100644
--- a/src/app/persistence_service.h
+++ b/src/app/persistence_service.h
@@ -31,6 +31,7 @@ struct PersistenceEvent {
std::uint64_t account_generation = 0;
std::uint64_t revision = 0;
StorageError error = StorageError::kNone;
+ std::string message; // the store's reason when the load or save failed
PreferencesLoadStatus preferences_status = PreferencesLoadStatus::kLoaded;
std::optional<Preferences> preferences;
std::optional<OrganizationSnapshot> organization;
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index b702efb..11b7e80 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -67,6 +67,11 @@ Controller::Controller(Simulation& model, steam::AuthBackend& backend, SessionRe
stores_(*owned_stores_), installs_(installs), cloud_(cloud), runtime_(runtime), auth_log_(std::move(auth_log)) {
Start(persistence_service);
}
+void Controller::SetPersistenceLog(std::function<void(const std::string&)> log) {
+ persistence_log_ = std::move(log);
+ if (persistence_) persistence_->SetLog(persistence_log_);
+}
+
void Controller::Start(app::PersistenceService* persistence_service) {
if (model_.state().simulation_mode) return;
app_details_ = stores_.details(Store::kSteam);
@@ -76,7 +81,10 @@ void Controller::Start(app::PersistenceService* persistence_service) {
service_ = stores_.steam_account();
phase_ = Phase::Restore;
Update(AuthState::Restoring,{},true);
- if(persistence_service) persistence_=std::make_unique<app::PersistenceController>(model_,*persistence_service);
+ if(persistence_service) {
+ persistence_=std::make_unique<app::PersistenceController>(model_,*persistence_service);
+ persistence_->SetLog(persistence_log_);
+ }
request_ = service_->RestoreSession();
// Every other store's library loads now, next to Steam's.
if (library_)
diff --git a/src/homebrew/controller.hpp b/src/homebrew/controller.hpp
index bac4cc5..ef9b213 100644
--- a/src/homebrew/controller.hpp
+++ b/src/homebrew/controller.hpp
@@ -53,6 +53,9 @@ class Controller {
void SetSelfUpdate(update::UpdateService* self_update) { self_update_ = self_update; }
// Receives one line per shutdown step with how long it took, so a quit that hangs names the step.
void SetShutdownLog(std::function<void(const std::string&)> log) { shutdown_log_ = std::move(log); }
+ // Preferences and organization load/save failures (app::PersistenceController::SetLog). The first loads
+ // report on a later Tick, so setting it right after construction still sees them.
+ void SetPersistenceLog(std::function<void(const std::string&)> log);
// The player turned "Stay signed in" on or off: the host moves the Steam session to disk or memory.
void SetStaySignedIn(std::function<void(bool)> apply) { stay_signed_in_ = std::move(apply); }
// Counts changes to the account's Steam licenses (steam::CmLicenseChanges): the library refreshes
@@ -107,6 +110,7 @@ class Controller {
void TickSelfUpdate();
void TickLicenseChanges();
std::function<void(const std::string&)> shutdown_log_;
+ std::function<void(const std::string&)> persistence_log_;
std::function<void(bool)> stay_signed_in_;
std::function<std::uint64_t()> license_changes_;
std::chrono::steady_clock::duration license_refresh_delay_{};
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cpp
index 63edba7..8b5cdef 100644
--- a/src/homebrew/ps5.cpp
+++ b/src/homebrew/ps5.cpp
@@ -702,6 +702,8 @@ int main() {
// A game bought or added to the library elsewhere: Steam pushes the new license list.
services.SetLicenseChanges([steam_cm] { return playden::steam::CmLicenseChanges(*steam_cm); });
services.SetShutdownLog([](const std::string& line) { playden::app::AppendLogLine(log_root, "launch.log", line); });
+ // "Saved UI data is unavailable" names no file or reason: the log does.
+ services.SetPersistenceLog([](const std::string& line) { playden::app::AppendLogLine(log_root, "launch.log", line); });
services.SetStaySignedIn([&sessions](bool stay) {
const auto moved = sessions.SetPersist(stay);
playden::app::AppendLogLine(log_root, "auth.log", std::string("stay signed in ") + (stay ? "on" : "off") +
diff --git a/tests/persistence_controller_test.cpp b/tests/persistence_controller_test.cpp
index 2965405..79e3ea8 100644
--- a/tests/persistence_controller_test.cpp
+++ b/tests/persistence_controller_test.cpp
@@ -11,6 +11,7 @@
#include <string>
#include <sys/stat.h>
#include <thread>
+#include <vector>
#include <unistd.h>
#include "steam_id.h"
@@ -359,6 +360,40 @@ void InitialPreferencesFailureRetriesWithoutOverwritingUnknownData() {
} // namespace
+// "Saved UI data is unavailable" names no file or reason, so the log does: one line per new failure, with the
+// store's message, and one when the same kind of save works again.
+void LogsSaveFailuresOnceAndRecovery() {
+ TemporaryDirectory directory;
+ Storage storage(directory.path());
+ PreferencesStore preferences(storage);
+ Repository repository;
+ repository.save_error = StorageError::kWriteFailed;
+ PersistenceService service(preferences, repository);
+ Simulation model({}, {}, ModelMode::Live);
+ PersistenceController controller(model, service);
+ std::vector<std::string> lines;
+ controller.SetLog([&lines](const std::string& line) { lines.push_back(line); });
+ service.WaitIdle();
+ controller.Tick();
+ const GameId local = GameId::Local("0b8f6c1e-4d2a-4f3b-9a1c-2e5d7f8a9b0c");
+ model.UpdateLibrary({{{local, "Imported game", {}, {}, {}, {}, {}}}, false, {}, false, false, {}, Store::kLocal});
+ assert(model.action("select:" + ToKey(local)));
+ assert(model.action("square"));
+ Wait(controller, [&] { return !lines.empty(); });
+ assert(lines.size() == 1 && lines[0] == "organization save failed: write failed: save");
+ // The same failure again is not logged twice.
+ assert(model.action("square"));
+ const int saves = repository.saves.load();
+ Wait(controller, [&] { return repository.saves.load() > saves; });
+ service.WaitIdle();
+ controller.Tick();
+ assert(lines.size() == 1);
+ repository.save_error = StorageError::kNone;
+ assert(model.action("square"));
+ Wait(controller, [&] { return lines.size() == 2; });
+ assert(lines[1] == "organization save works again");
+}
+
int main() {
PendingLoadReplaysLocalEditAndSavesMergedSnapshot();
SignOutClearKeepsOrganization();
@@ -368,4 +403,5 @@ int main() {
ShutdownWaitsForLoadBeforeMergingFinalEdit();
InvalidMergedLoadStaysUnsavedUntilEditAndRetryResolveIt();
InitialPreferencesFailureRetriesWithoutOverwritingUnknownData();
+ LogsSaveFailuresOnceAndRecovery();
}