From 586b2493f90a5b13396f118590e5d6148663faca Mon Sep 17 00:00:00 2001 From: lampysprites Date: Sun, 12 Dec 2021 18:57:51 +0700 Subject: [PATCH 1/9] [lua] Show more specific websocket errors --- src/app/script/websocket_class.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/app/script/websocket_class.cpp b/src/app/script/websocket_class.cpp index 6be1956f5..2306d0809 100644 --- a/src/app/script/websocket_class.cpp +++ b/src/app/script/websocket_class.cpp @@ -127,6 +127,11 @@ int WebSocket_gc(lua_State* L) int WebSocket_sendText(lua_State* L) { auto ws = get_ptr(L, 1); + + if (ws->getReadyState() != ix::ReadyState::Open) { + return luaL_error(L, "Websocket is not connected, can't send text"); + } + std::stringstream data; int argc = lua_gettop(L); @@ -137,8 +142,7 @@ int WebSocket_sendText(lua_State* L) } if (!ws->sendText(data.str()).success) { - lua_pushstring(L, "Websocket error"); - lua_error(L); + return luaL_error(L, "Websocket failed to send text"); } return 0; } @@ -146,6 +150,11 @@ int WebSocket_sendText(lua_State* L) int WebSocket_sendBinary(lua_State* L) { auto ws = get_ptr(L, 1); + + if (ws->getReadyState() != ix::ReadyState::Open) { + return luaL_error(L, "Websocket is not connected, can't send data"); + } + std::stringstream data; int argc = lua_gettop(L); @@ -154,10 +163,9 @@ int WebSocket_sendBinary(lua_State* L) const char* buf = lua_tolstring(L, i, &bufLen); data.write(buf, bufLen); } - + if (!ws->sendBinary(data.str()).success) { - lua_pushstring(L, "Websocket error"); - lua_error(L); + return luaL_error(L, "Websocket failed to send data"); } return 0; } @@ -165,13 +173,17 @@ int WebSocket_sendBinary(lua_State* L) int WebSocket_sendPing(lua_State* L) { auto ws = get_ptr(L, 1); + + if (ws->getReadyState() != ix::ReadyState::Open) { + return luaL_error(L, "Websocket is not connected, can't send ping"); + } + size_t bufLen; const char* buf = lua_tolstring(L, 2, &bufLen); std::string data(buf, bufLen); if (!ws->ping(data).success) { - lua_pushstring(L, "Websocket error"); - lua_error(L); + return luaL_error(L, "Websocket failed to send ping"); } return 0; } From 3035d002835507b10664d3b9531f83939559dec5 Mon Sep 17 00:00:00 2001 From: lampysprites Date: Sun, 12 Dec 2021 19:20:12 +0700 Subject: [PATCH 2/9] [lua] Show errors that happen inside App.transaction --- src/app/script/app_object.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/script/app_object.cpp b/src/app/script/app_object.cpp index 2792cee76..cbb93d882 100644 --- a/src/app/script/app_object.cpp +++ b/src/app/script/app_object.cpp @@ -135,10 +135,12 @@ int App_transaction(lua_State* L) int nresults = 0; if (lua_isfunction(L, 1)) { Tx tx; // Create a new transaction so it exists in the whole - // duration of the argument function call. + // duration of the argument function call. lua_pushvalue(L, -1); if (lua_pcall(L, 0, LUA_MULTRET, 0) == LUA_OK) tx.commit(); + else + return lua_error(L); // pcall already put an error object on the stack nresults = lua_gettop(L) - top; } return nresults; From 9340ca387d3f7f692c042778075567381fe7bb58 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 15 Dec 2021 20:19:26 -0300 Subject: [PATCH 3/9] [lua] Minor change in error messages Websocket -> WebSocket --- src/app/script/websocket_class.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/script/websocket_class.cpp b/src/app/script/websocket_class.cpp index 2306d0809..e0ff1a9ce 100644 --- a/src/app/script/websocket_class.cpp +++ b/src/app/script/websocket_class.cpp @@ -129,7 +129,7 @@ int WebSocket_sendText(lua_State* L) auto ws = get_ptr(L, 1); if (ws->getReadyState() != ix::ReadyState::Open) { - return luaL_error(L, "Websocket is not connected, can't send text"); + return luaL_error(L, "WebSocket is not connected, can't send text"); } std::stringstream data; @@ -142,7 +142,7 @@ int WebSocket_sendText(lua_State* L) } if (!ws->sendText(data.str()).success) { - return luaL_error(L, "Websocket failed to send text"); + return luaL_error(L, "WebSocket failed to send text"); } return 0; } @@ -152,8 +152,8 @@ int WebSocket_sendBinary(lua_State* L) auto ws = get_ptr(L, 1); if (ws->getReadyState() != ix::ReadyState::Open) { - return luaL_error(L, "Websocket is not connected, can't send data"); - } + return luaL_error(L, "WebSocket is not connected, can't send data"); + } std::stringstream data; int argc = lua_gettop(L); @@ -163,9 +163,9 @@ int WebSocket_sendBinary(lua_State* L) const char* buf = lua_tolstring(L, i, &bufLen); data.write(buf, bufLen); } - + if (!ws->sendBinary(data.str()).success) { - return luaL_error(L, "Websocket failed to send data"); + return luaL_error(L, "WebSocket failed to send data"); } return 0; } @@ -175,7 +175,7 @@ int WebSocket_sendPing(lua_State* L) auto ws = get_ptr(L, 1); if (ws->getReadyState() != ix::ReadyState::Open) { - return luaL_error(L, "Websocket is not connected, can't send ping"); + return luaL_error(L, "WebSocket is not connected, can't send ping"); } size_t bufLen; @@ -183,7 +183,7 @@ int WebSocket_sendPing(lua_State* L) std::string data(buf, bufLen); if (!ws->ping(data).success) { - return luaL_error(L, "Websocket failed to send ping"); + return luaL_error(L, "WebSocket failed to send ping"); } return 0; } From 2be9403a480a6e07d9307a222d241aa747db9ca8 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 21 Dec 2021 13:40:38 -0300 Subject: [PATCH 4/9] Rename the Sentry crash handler to aseprite_crashpad_handler (#2857) --- src/app/sentry_wrapper.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app/sentry_wrapper.cpp b/src/app/sentry_wrapper.cpp index 40e3427d6..3dd8b3af9 100644 --- a/src/app/sentry_wrapper.cpp +++ b/src/app/sentry_wrapper.cpp @@ -97,13 +97,26 @@ bool Sentry::areThereCrashesToReport() void Sentry::setupDirs(sentry_options_t* options) { + // The expected handler executable name is aseprite_crashpad_handler (.exe) + const std::string handler = + base::join_path(base::get_file_path(base::get_app_path()), + "aseprite_crashpad_handler" +#if LAF_WINDOWS + ".exe" +#endif + ); + + // The crash database will be located in the user directory as the + // "crashdb" directory (along with "sessions", "extensions", etc.) ResourceFinder rf; rf.includeUserDir("crashdb"); const std::string dir = rf.getFirstOrCreateDefault(); -#if SENTRY_PLATFORM_WINDOWS +#if LAF_WINDOWS + sentry_options_set_handler_pathw(options, base::from_utf8(handler).c_str()); sentry_options_set_database_pathw(options, base::from_utf8(dir).c_str()); #else + sentry_options_set_handler_path(options, handler.c_str()); sentry_options_set_database_path(options, dir.c_str()); #endif From a7a344339c2d74eb101cc5a70cce03cf6648401c Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 22 Dec 2021 17:02:34 -0300 Subject: [PATCH 5/9] Update laf & clip submodules --- laf | 2 +- src/clip | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/laf b/laf index e1d2d2341..e3b0e2a30 160000 --- a/laf +++ b/laf @@ -1 +1 @@ -Subproject commit e1d2d23413e9028bfa6f0b08b74d9c57b3eed4a6 +Subproject commit e3b0e2a3004136e449b43a8d21e1450b4b4c86f9 diff --git a/src/clip b/src/clip index a65a9e543..4b8e4cf03 160000 --- a/src/clip +++ b/src/clip @@ -1 +1 @@ -Subproject commit a65a9e543e9a270bb7c58789d15d027bbd8efb2a +Subproject commit 4b8e4cf03836fb2bd48d64434e6271be7e6ec728 From 3fba3032915c9979a6dd5c5f25c7198959bc0be9 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 22 Dec 2021 17:03:16 -0300 Subject: [PATCH 6/9] Define some variables for Sentry when using curl as transport --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a0af4815..7b359964a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -315,6 +315,8 @@ if(REQUIRE_CURL) if(USE_SHARED_CURL) find_package(CURL REQUIRED) else() + set(CURL_FOUND 1) + set(CURL_LIBRARY libcurl) set(CURL_LIBRARIES libcurl) set(CURL_INCLUDE_DIRS ${CURL_DIR}/include) endif() From 6836911661ba0fd069fdca00785948e348e1c6a7 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 22 Dec 2021 19:08:43 -0300 Subject: [PATCH 7/9] Don't define HAVE_CONFIG_H and include "src" directory globally Avoid using include_directories() and add_definitions() as much as possible. This change was made to avoid a problem using HAVE_CONFIG_H on Sentry breakpad implementation where HAVE_CONFIG_H is used (but our config.h is different from the expected one in breakpad). --- CMakeLists.txt | 8 +++++--- src/ver/CMakeLists.txt | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b359964a..968c429fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -329,9 +329,6 @@ include_directories(${SIMPLEINI_DIR}) # Third parties add_subdirectory(third_party) -# LAF libraries + Aseprite are compiled with config.h -include_directories(src) -add_definitions(-DHAVE_CONFIG_H) if(ENABLE_MEMLEAK) add_definitions(-DLAF_MEMLEAK) endif() @@ -340,6 +337,11 @@ set(LAF_WITH_TESTS ${ENABLE_TESTS} CACHE BOOL "Enable LAF tests") set(UNDO_TESTS ${ENABLE_TESTS} CACHE BOOL "Enable undo tests") add_subdirectory(laf) + +# LAF libraries + Aseprite are compiled with config.h +target_include_directories(laf-base PUBLIC src) +target_compile_definitions(laf-base PUBLIC HAVE_CONFIG_H) + add_subdirectory(src) ###################################################################### diff --git a/src/ver/CMakeLists.txt b/src/ver/CMakeLists.txt index 238b3cfd4..bb5b32c65 100644 --- a/src/ver/CMakeLists.txt +++ b/src/ver/CMakeLists.txt @@ -15,4 +15,4 @@ endif() add_library(ver-lib info.c ${gen_ver_fn}) add_dependencies(ver-lib generated_version_h) -target_include_directories(ver-lib PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") +target_include_directories(ver-lib PRIVATE .. "${CMAKE_CURRENT_BINARY_DIR}") From 02de9be1abf3983f013acc34a436ae68efae7e35 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 23 Dec 2021 21:38:17 -0300 Subject: [PATCH 8/9] Rename src/tests/test.h -> src/tests/app_test.h to avoid confusion with observable tests/test.h --- cmake/FindTests.cmake | 11 ++++++++--- src/app/cli/cli_tests.cpp | 2 +- src/app/cli/filter_layer_tests.cpp | 2 +- src/app/color_tests.cpp | 2 +- src/app/context_tests.cpp | 2 +- src/app/doc_api_tests.cpp | 2 +- src/app/doc_range_tests.cpp | 2 +- src/app/errno_tests.cpp | 2 +- src/app/file/file_tests.cpp | 2 +- src/app/file/split_filename_tests.cpp | 2 +- src/app/filename_formatter_tests.cpp | 2 +- src/app/ini_file_tests.cpp | 2 +- src/clip | 2 +- src/observable | 2 +- src/tests/{test.h => app_test.h} | 0 src/ui/accelerator_ui_tests.cpp | 2 +- src/ui/grid_ui_tests.cpp | 2 +- src/undo | 2 +- 18 files changed, 24 insertions(+), 19 deletions(-) rename src/tests/{test.h => app_test.h} (100%) diff --git a/cmake/FindTests.cmake b/cmake/FindTests.cmake index eeb354d44..3ff9a4387 100644 --- a/cmake/FindTests.cmake +++ b/cmake/FindTests.cmake @@ -1,3 +1,4 @@ +# Copyright (C) 2021 Igara Studio S.A. # Copyright (C) 2001-2016 David Capello # Find tests and add rules to compile them and run them @@ -5,9 +6,6 @@ function(find_tests dir dependencies) file(GLOB tests ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*_tests.cpp) list(REMOVE_AT ARGV 0) - # Add gtest include directory so we can #include in tests source code - include_directories(${CMAKE_SOURCE_DIR}/third_party/gtest/include) - # See if the test is linked with "laf-os" library. list(FIND dependencies laf-os link_with_os) if(link_with_os) @@ -28,6 +26,13 @@ function(find_tests dir dependencies) target_link_libraries(${testname} gtest ${ARGV} ${PLATFORM_LIBS}) + target_include_directories(${testname} PUBLIC + # So we can include "tests/app_test.h" + ${CMAKE_SOURCE_DIR}/src + # Add gtest include directory so we can #include + # in tests source code + ${CMAKE_SOURCE_DIR}/third_party/gtest/include) + if(extra_definitions) set_target_properties(${testname} PROPERTIES COMPILE_FLAGS ${extra_definitions}) diff --git a/src/app/cli/cli_tests.cpp b/src/app/cli/cli_tests.cpp index d16effeba..506864fd9 100644 --- a/src/app/cli/cli_tests.cpp +++ b/src/app/cli/cli_tests.cpp @@ -5,7 +5,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/cli/app_options.h" #include "app/cli/cli_processor.h" diff --git a/src/app/cli/filter_layer_tests.cpp b/src/app/cli/filter_layer_tests.cpp index 51299e16c..96d8b5733 100644 --- a/src/app/cli/filter_layer_tests.cpp +++ b/src/app/cli/filter_layer_tests.cpp @@ -4,7 +4,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/cli/cli_processor.h" #include "doc/layer.h" diff --git a/src/app/color_tests.cpp b/src/app/color_tests.cpp index 0a3a5b4ad..153f07480 100644 --- a/src/app/color_tests.cpp +++ b/src/app/color_tests.cpp @@ -4,7 +4,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/color.h" diff --git a/src/app/context_tests.cpp b/src/app/context_tests.cpp index b93ac186b..6929dab2c 100644 --- a/src/app/context_tests.cpp +++ b/src/app/context_tests.cpp @@ -4,7 +4,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/context.h" #include "app/doc.h" diff --git a/src/app/doc_api_tests.cpp b/src/app/doc_api_tests.cpp index e4505f81c..4518c66ff 100644 --- a/src/app/doc_api_tests.cpp +++ b/src/app/doc_api_tests.cpp @@ -5,7 +5,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/context.h" #include "app/doc.h" diff --git a/src/app/doc_range_tests.cpp b/src/app/doc_range_tests.cpp index a9f07d5cb..eab287aec 100644 --- a/src/app/doc_range_tests.cpp +++ b/src/app/doc_range_tests.cpp @@ -4,7 +4,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/context.h" #include "app/doc.h" diff --git a/src/app/errno_tests.cpp b/src/app/errno_tests.cpp index ebf7e4b62..153aa31bd 100644 --- a/src/app/errno_tests.cpp +++ b/src/app/errno_tests.cpp @@ -4,7 +4,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include #include "base/thread.h" diff --git a/src/app/file/file_tests.cpp b/src/app/file/file_tests.cpp index e8f948291..33fb3e391 100644 --- a/src/app/file/file_tests.cpp +++ b/src/app/file/file_tests.cpp @@ -5,7 +5,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/app.h" #include "app/context.h" diff --git a/src/app/file/split_filename_tests.cpp b/src/app/file/split_filename_tests.cpp index 97aeb321e..4be32614f 100644 --- a/src/app/file/split_filename_tests.cpp +++ b/src/app/file/split_filename_tests.cpp @@ -4,7 +4,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/file/split_filename.h" diff --git a/src/app/filename_formatter_tests.cpp b/src/app/filename_formatter_tests.cpp index e01371891..5ae2bc708 100644 --- a/src/app/filename_formatter_tests.cpp +++ b/src/app/filename_formatter_tests.cpp @@ -4,7 +4,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/filename_formatter.h" diff --git a/src/app/ini_file_tests.cpp b/src/app/ini_file_tests.cpp index a8033c5e2..87f0f01f6 100644 --- a/src/app/ini_file_tests.cpp +++ b/src/app/ini_file_tests.cpp @@ -4,7 +4,7 @@ // This program is distributed under the terms of // the End-User License Agreement for Aseprite. -#include "tests/test.h" +#include "tests/app_test.h" #include "app/ini_file.h" #include "base/fs.h" diff --git a/src/clip b/src/clip index 4b8e4cf03..c46c49141 160000 --- a/src/clip +++ b/src/clip @@ -1 +1 @@ -Subproject commit 4b8e4cf03836fb2bd48d64434e6271be7e6ec728 +Subproject commit c46c49141f72dd753b260eea4e6d7b37413f0ff6 diff --git a/src/observable b/src/observable index bddbeed8b..8e03c3cb0 160000 --- a/src/observable +++ b/src/observable @@ -1 +1 @@ -Subproject commit bddbeed8b94d2639fa945bdf14a90d7afbd58506 +Subproject commit 8e03c3cb060120b25517503e6c1d9072686d1cd3 diff --git a/src/tests/test.h b/src/tests/app_test.h similarity index 100% rename from src/tests/test.h rename to src/tests/app_test.h diff --git a/src/ui/accelerator_ui_tests.cpp b/src/ui/accelerator_ui_tests.cpp index 6ad2e13b0..c4d364831 100644 --- a/src/ui/accelerator_ui_tests.cpp +++ b/src/ui/accelerator_ui_tests.cpp @@ -5,7 +5,7 @@ // Read LICENSE.txt for more information. #define TEST_GUI -#include "tests/test.h" +#include "tests/app_test.h" using namespace ui; diff --git a/src/ui/grid_ui_tests.cpp b/src/ui/grid_ui_tests.cpp index 4c53d53f8..0e3c0447e 100644 --- a/src/ui/grid_ui_tests.cpp +++ b/src/ui/grid_ui_tests.cpp @@ -5,7 +5,7 @@ // Read LICENSE.txt for more information. #define TEST_GUI -#include "tests/test.h" +#include "tests/app_test.h" #include "gfx/rect_io.h" #include "gfx/size.h" diff --git a/src/undo b/src/undo index e72730478..3cf8f20d0 160000 --- a/src/undo +++ b/src/undo @@ -1 +1 @@ -Subproject commit e72730478aa6d4dc3be0c914058a7e0561aabe1e +Subproject commit 3cf8f20d08bf38b06b8e0e75757a18e31ddb12d9 From bc22073a4eda909a150071cc0baec39f4123ebda Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 5 Jan 2022 20:14:56 -0300 Subject: [PATCH 9/9] Update laf module --- laf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/laf b/laf index e3b0e2a30..56b72b6b0 160000 --- a/laf +++ b/laf @@ -1 +1 @@ -Subproject commit e3b0e2a3004136e449b43a8d21e1450b4b4c86f9 +Subproject commit 56b72b6b03f8411115c4bd201b6896340eee08e1