From 00f251753e41bd1c65f9e4160fe5b267ce8385ba Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 30 Jun 2021 02:43:36 +0200 Subject: Use coeurl for networking Something is still wrong on shutdown, need to debug that. And CI will fail. --- src/ChatPage.cpp | 4 ++-- src/LoginPage.cpp | 13 +++++-------- src/RegisterPage.cpp | 17 +++++++---------- src/ui/RoomSettings.cpp | 2 +- 4 files changed, 15 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 0f16f205..ca36232e 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -550,7 +550,7 @@ ChatPage::startInitialSync() nhlog::net()->error("initial sync error: {} {} {} {}", err->parse_error, status_code, - err->error_code.message(), + err->error_code, err_code); // non http related errors @@ -677,7 +677,7 @@ ChatPage::trySync() nhlog::net()->error("initial sync error: {} {} {} {}", err->parse_error, status_code, - err->error_code.message(), + err->error_code, err_code); emit tryDelayedSyncCb(); return; diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index c914d66f..f53d81ba 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -263,9 +263,7 @@ LoginPage::onMatrixIdEntered() http::client()->well_known([this](const mtx::responses::WellKnown &res, mtx::http::RequestErr err) { if (err) { - using namespace boost::beast::http; - - if (err->status_code == status::not_found) { + if (err->status_code == 404) { nhlog::net()->info("Autodiscovery: No .well-known."); checkHomeserverVersion(); return; @@ -282,8 +280,9 @@ LoginPage::onMatrixIdEntered() emit versionErrorCb(tr("Autodiscovery failed. Unknown error when " "requesting .well-known.")); nhlog::net()->error("Autodiscovery failed. Unknown error when " - "requesting .well-known. {}", - err->error_code.message()); + "requesting .well-known. {} {}", + err->status_code, + err->error_code); return; } @@ -301,9 +300,7 @@ LoginPage::checkHomeserverVersion() http::client()->versions( [this](const mtx::responses::Versions &, mtx::http::RequestErr err) { if (err) { - using namespace boost::beast::http; - - if (err->status_code == status::not_found) { + if (err->status_code == 404) { emit versionErrorCb(tr("The required endpoints were not found. " "Possibly not a Matrix server.")); return; diff --git a/src/RegisterPage.cpp b/src/RegisterPage.cpp index 36fd71a8..1588d07d 100644 --- a/src/RegisterPage.cpp +++ b/src/RegisterPage.cpp @@ -289,7 +289,7 @@ RegisterPage::RegisterPage(QWidget *parent) } // The server requires registration flows. - if (err->status_code == boost::beast::http::status::unauthorized) { + if (err->status_code == 401) { if (err->matrix_error.unauthorized.flows.empty()) { nhlog::net()->warn( "failed to retrieve registration flows: ({}) " @@ -431,9 +431,7 @@ RegisterPage::onRegisterButtonClicked() [this, username, password](const mtx::responses::WellKnown &res, mtx::http::RequestErr err) { if (err) { - using namespace boost::beast::http; - - if (err->status_code == status::not_found) { + if (err->status_code == 404) { nhlog::net()->info("Autodiscovery: No .well-known."); checkVersionAndRegister(username, password); return; @@ -450,8 +448,9 @@ RegisterPage::onRegisterButtonClicked() emit versionErrorCb(tr("Autodiscovery failed. Unknown error when " "requesting .well-known.")); nhlog::net()->error("Autodiscovery failed. Unknown error when " - "requesting .well-known. {}", - err->error_code.message()); + "requesting .well-known. {} {}", + err->status_code, + err->error_code); return; } @@ -471,9 +470,7 @@ RegisterPage::checkVersionAndRegister(const std::string &username, const std::st http::client()->versions( [this, username, password](const mtx::responses::Versions &, mtx::http::RequestErr err) { if (err) { - using namespace boost::beast::http; - - if (err->status_code == status::not_found) { + if (err->status_code == 404) { emit versionErrorCb(tr("The required endpoints were not found. " "Possibly not a Matrix server.")); return; @@ -504,7 +501,7 @@ RegisterPage::checkVersionAndRegister(const std::string &username, const std::st } // The server requires registration flows. - if (err->status_code == boost::beast::http::status::unauthorized) { + if (err->status_code == 401) { if (err->matrix_error.unauthorized.flows.empty()) { nhlog::net()->warn( "failed to retrieve registration flows1: ({}) " diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp index 0bc8759e..f78ef09b 100644 --- a/src/ui/RoomSettings.cpp +++ b/src/ui/RoomSettings.cpp @@ -181,7 +181,7 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent) roomid_.toStdString(), [this](const mtx::pushrules::PushRule &rule, mtx::http::RequestErr &err) { if (err) { - if (err->status_code == boost::beast::http::status::not_found) + if (err->status_code == 404) http::client()->get_pushrules( "global", "room", -- cgit 1.5.1 From 2c307a4dee59490615ce57fac1001256ec5b5d3d Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 30 Jun 2021 12:21:57 +0200 Subject: Fix error message for /sync --- src/ChatPage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index ca36232e..6003eb85 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -674,7 +674,7 @@ ChatPage::trySync() return; } - nhlog::net()->error("initial sync error: {} {} {} {}", + nhlog::net()->error("sync error: {} {} {} {}", err->parse_error, status_code, err->error_code, -- cgit 1.5.1 From 590395a08b60c74c0743fd7dcce8b93ad557428d Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 30 Jun 2021 12:22:22 +0200 Subject: Fix too many newlines in reply fallback --- src/timeline/InputBar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index c309daab..b0747a7c 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -296,7 +296,7 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown, bool rainbowify) firstLine = false; body = QString("> <%1> %2\n").arg(related.quoted_user).arg(line); } else { - body = QString("%1\n> %2\n").arg(body).arg(line); + body += QString("> %1\n").arg(line); } } -- cgit 1.5.1 From 9f7064676c238585713144d9b52b8aa789eb9fd0 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 30 Jun 2021 15:01:41 +0200 Subject: Get rid of boost dependency for stacktraces --- CMakeLists.txt | 9 ++++++++- cmake/nheko.h | 5 ++++- src/Olm.h | 2 -- src/main.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 48 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 320b4678..4b023d48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -265,7 +265,10 @@ set(PROJECT_VERSION ${CPACK_PACKAGE_VERSION}) message(STATUS "Version: ${PROJECT_VERSION}") cmake_host_system_information(RESULT BUILD_HOST QUERY HOSTNAME) -set(BUILD_USER $ENV{USER}) + +include(CheckSymbolExists) +check_symbol_exists(backtrace_symbols_fd "execinfo.h" HAVE_BACKTRACE_SYMBOLS_FD) + configure_file(cmake/nheko.h config/nheko.h) @@ -607,6 +610,10 @@ if(WIN32) target_compile_definitions(nheko PRIVATE _WIN32_WINNT=0x0601) else() add_executable (nheko ${OS_BUNDLE} ${NHEKO_DEPS}) + + if (HAVE_BACKTRACE_SYMBOLS_FD AND NOT CMAKE_BUILD_TYPE STREQUAL "Release") + set_target_properties(nheko PROPERTIES ENABLE_EXPORTS ON) + endif() endif() if(APPLE) diff --git a/cmake/nheko.h b/cmake/nheko.h index bf1a54fe..c2329917 100644 --- a/cmake/nheko.h +++ b/cmake/nheko.h @@ -1,6 +1,9 @@ namespace nheko { constexpr auto version = "${PROJECT_VERSION}"; -constexpr auto build_user = "${BUILD_USER}@${BUILD_HOST}"; constexpr auto build_os = "${CMAKE_HOST_SYSTEM_NAME}"; constexpr auto enable_debug_log = ${SPDLOG_DEBUG_ON}; } + +// clang-format off +#define HAVE_BACKTRACE_SYMBOLS_FD ${HAVE_BACKTRACE_SYMBOLS_FD} +// clang-format on diff --git a/src/Olm.h b/src/Olm.h index d356cb55..8479f4f2 100644 --- a/src/Olm.h +++ b/src/Olm.h @@ -4,8 +4,6 @@ #pragma once -#include - #include #include #include diff --git a/src/main.cpp b/src/main.cpp index fe1a9ee3..f4484f94 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,15 +40,48 @@ QQmlDebuggingEnabler enabler; #endif -#if defined(Q_OS_LINUX) -#include +#if HAVE_BACKTRACE_SYMBOLS_FD #include +#include +#include +#include void stacktraceHandler(int signum) { std::signal(signum, SIG_DFL); - boost::stacktrace::safe_dump_to("./nheko-backtrace.dump"); + + // boost::stacktrace::safe_dump_to("./nheko-backtrace.dump"); + + // see + // https://stackoverflow.com/questions/77005/how-to-automatically-generate-a-stacktrace-when-my-program-crashes/77336#77336 + void *array[50]; + size_t size; + + // get void*'s for all entries on the stack + size = backtrace(array, 50); + + // print out all the frames to stderr + fprintf(stderr, "Error: signal %d:\n", signum); + backtrace_symbols_fd(array, size, STDERR_FILENO); + + int file = ::open("/tmp/nheko-crash.dump", + O_CREAT | O_WRONLY | O_TRUNC +#if defined(S_IWUSR) && defined(S_IRUSR) + , + S_IWUSR | S_IRUSR +#elif defined(S_IWRITE) && defined(S_IREAD) + , + S_IWRITE | S_IREAD +#endif + ); + if (file != -1) { + constexpr char header[] = "Error: signal\n"; + write(file, header, std::size(header) - 1); + backtrace_symbols_fd(array, size, file); + close(file); + } + std::raise(SIGABRT); } -- cgit 1.5.1 From 66e69d7f2b8568c304bdc280d15f543e49d1721c Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 30 Jun 2021 15:28:44 +0200 Subject: Ignore return value of write() in signal handler --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index f4484f94..29e93d49 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,8 +76,8 @@ stacktraceHandler(int signum) #endif ); if (file != -1) { - constexpr char header[] = "Error: signal\n"; - write(file, header, std::size(header) - 1); + constexpr char header[] = "Error: signal\n"; + [[maybe_unused]] auto ret = write(file, header, std::size(header) - 1); backtrace_symbols_fd(array, size, file); close(file); } -- cgit 1.5.1