Linux + iPhone Continuity / iMessage / SMS
fix(protocol): report file-send connection failures with operation IDs
Nick Pisania7eba88b2ec8
diff --git a/src/core/src/net.cpp b/src/core/src/net.cppindex 32d8c2b..dba9b74 100644--- a/src/core/src/net.cpp+++ b/src/core/src/net.cpp@@ -1336,8 +1336,7 @@ namespace tether {nlohmann::json event;event["command"] = "bt_send_result";event["thread"] = thread;- if (!operation_id.empty())- event["operation_id"] = operation_id;+ set_operation_id(event, operation_id);event["success"] = bluetooth::send_message(thread, body, sent, err);if (event["success"]) {nlohmann::json message = bluetooth::to_json(sent);@@ -1670,21 +1669,22 @@ namespace tether {std::string path = j["path"];const std::string operation_id = j.value("operation_id", std::string{});std::thread([path, operation_id]() {+ nlohmann::json resp;+ resp["command"] = "file_send_complete";+ set_operation_id(resp, operation_id);Client local;if (local.connect("", 0)) { // connects correctly via unix socketstd::string err;bool ok = local.send_file(path, err);- nlohmann::json resp;- resp["command"] = "file_send_complete";resp["success"] = ok;resp["message"] =ok ? tr_format(_("Sent {}"), std::filesystem::path(path).filename().string()): tr_format(_("Send failed: {}"), err.empty() ? _("unknown error") : err);- if (!operation_id.empty())- resp["operation_id"] = operation_id;-- broadcast_local_event(resp.dump());+ } else {+ resp["success"] = false;+ resp["message"] = tr_format(_("Send failed: {}"), _("Could not reach the Tether daemon."));}+ broadcast_local_event(resp.dump());}).detach();continue; // skip the "OK\n" below because we reply asynchronously}diff --git a/test/test_net.cpp b/test/test_net.cppindex 2e00d73..d6d45de 100644--- a/test/test_net.cpp+++ b/test/test_net.cpp@@ -466,6 +466,25 @@ namespace {elseEXPECT_EQ(result.value("operation_id", ""), operation_id);}++ // The subscribed socket stays open, but an oversized runtime path makes+ // the worker's internal Client::connect fail without spawning a daemon.+ {+ ScopedEnvVar unconnectable_runtime("XDG_RUNTIME_DIR", runtime_dir + "/" + std::string(110, 'x'));+ const std::string payload = nlohmann::json{{"command", "send_file"},+ {"path", runtime_dir + "/missing.txt"},+ {"operation_id", "web-connect-failure"}}+ .dump() ++ "\n";+ ASSERT_EQ(write(client, payload.data(), payload.size()), static_cast<ssize_t>(payload.size()));+ const std::string line = read_socket_line(client);+ ASSERT_FALSE(line.empty()) << "internal connect failure must produce a terminal event";+ const auto result = nlohmann::json::parse(line);+ EXPECT_EQ(result.value("command", ""), "file_send_complete");+ EXPECT_FALSE(result.value("success", true));+ EXPECT_FALSE(result.value("message", "").empty());+ EXPECT_EQ(result.value("operation_id", ""), "web-connect-failure");+ }close(client);}