From 9e6a1225dbc63cef35c9d0e627e33d2e7efe69d2 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Mon, 21 Sep 2020 12:05:31 +0100 Subject: [PATCH] Catch exception when creating app settings objects These settings objects could be created in a constructor/destructor so we should catch the exception since those are noexcept. Also change the settings trace to match the other kicad traces as KICAD_SETTINGS --- common/project/project_file.cpp | 1 - common/settings/color_settings.cpp | 2 -- common/settings/common_settings.cpp | 3 --- common/settings/json_settings.cpp | 3 +-- common/settings/nested_settings.cpp | 2 -- common/settings/settings_manager.cpp | 6 ------ include/settings/json_settings.h | 8 ++++++++ include/settings/settings_manager.h | 14 +++++++++++++- include/trace_helpers.h | 2 +- pcbnew/footprint_editor_settings.cpp | 2 -- 10 files changed, 23 insertions(+), 20 deletions(-) diff --git a/common/project/project_file.cpp b/common/project/project_file.cpp index 31afbbb44b..d84330e036 100644 --- a/common/project/project_file.cpp +++ b/common/project/project_file.cpp @@ -28,7 +28,6 @@ #include #include -extern const char* traceSettings; ///! Update the schema version whenever a migration is required const int projectFileSchemaVersion = 1; diff --git a/common/settings/color_settings.cpp b/common/settings/color_settings.cpp index d19d5d886c..01bbc06a2e 100644 --- a/common/settings/color_settings.cpp +++ b/common/settings/color_settings.cpp @@ -25,8 +25,6 @@ #include -extern const char* traceSettings; - ///! Update the schema version whenever a migration is required const int colorsSchemaVersion = 1; diff --git a/common/settings/common_settings.cpp b/common/settings/common_settings.cpp index f81c4ce6c3..822a6afbc7 100644 --- a/common/settings/common_settings.cpp +++ b/common/settings/common_settings.cpp @@ -28,9 +28,6 @@ using KIGFX::MOUSE_DRAG_ACTION; -extern const char* traceSettings; - - ///! Update the schema version whenever a migration is required const int commonSchemaVersion = 1; diff --git a/common/settings/json_settings.cpp b/common/settings/json_settings.cpp index e27257f440..b9de808f32 100644 --- a/common/settings/json_settings.cpp +++ b/common/settings/json_settings.cpp @@ -33,8 +33,7 @@ #include #include -extern const char* traceSettings; - +const wxChar* const traceSettings = wxT( "KICAD_SETTINGS" ); JSON_SETTINGS::JSON_SETTINGS( const wxString& aFilename, SETTINGS_LOC aLocation, int aSchemaVersion, bool aCreateIfMissing, bool aCreateIfDefault, diff --git a/common/settings/nested_settings.cpp b/common/settings/nested_settings.cpp index b0f2c6acb9..813368f67c 100644 --- a/common/settings/nested_settings.cpp +++ b/common/settings/nested_settings.cpp @@ -22,8 +22,6 @@ #include -extern const char* traceSettings; - NESTED_SETTINGS::NESTED_SETTINGS( const std::string& aName, int aVersion, JSON_SETTINGS* aParent, const std::string& aPath ) : diff --git a/common/settings/settings_manager.cpp b/common/settings/settings_manager.cpp index 6eaeb39ff6..c5a9a7289c 100644 --- a/common/settings/settings_manager.cpp +++ b/common/settings/settings_manager.cpp @@ -41,12 +41,6 @@ #include -/** - * Flag to enable settings tracing - * @ingroup trace_env_vars - */ -const char* traceSettings = "SETTINGS"; - /// Project settings path will be + this #define PROJECT_BACKUPS_DIR_SUFFIX wxT( "-backups" ) diff --git a/include/settings/json_settings.h b/include/settings/json_settings.h index a768bcf5f8..b02d9ef99a 100644 --- a/include/settings/json_settings.h +++ b/include/settings/json_settings.h @@ -32,6 +32,14 @@ class NESTED_SETTINGS; class PARAM_BASE; class SETTINGS_MANAGER; +/** + * Flag to enable debug output of settings operations and management. + * + * Use "KICAD_SETTINGS" to enable. + * + * @ingroup trace_env_vars + */ +extern const wxChar* const traceSettings; enum class SETTINGS_LOC { USER, ///< The main config directory (e.g. ~/.config/kicad/) diff --git a/include/settings/settings_manager.h b/include/settings/settings_manager.h index ad4fc5026a..0b95cf7fbe 100644 --- a/include/settings/settings_manager.h +++ b/include/settings/settings_manager.h @@ -94,9 +94,21 @@ public: } ); if( it != m_settings.end() ) + { ret = dynamic_cast( it->get() ); + } else - ret = static_cast( RegisterSettings( new AppSettings, aLoadNow ) ); + { + try + { + ret = static_cast( RegisterSettings( new AppSettings, aLoadNow ) ); + } + catch( ... ) + { + wxLogTrace( traceSettings, "Unable to create application settings object" ); + } + + } return ret; } diff --git a/include/trace_helpers.h b/include/trace_helpers.h index 10651e8d5a..6d9266a462 100644 --- a/include/trace_helpers.h +++ b/include/trace_helpers.h @@ -177,7 +177,7 @@ extern const wxChar* const traceSchSheetPaths; /** * Flag to enable debug output of environment variable operations. * - * Use "KICAD_ENV_VARS" to enable + * Use "KICAD_ENV_VARS" to enable. * */ extern const wxChar* const traceEnvVars; diff --git a/pcbnew/footprint_editor_settings.cpp b/pcbnew/footprint_editor_settings.cpp index f7a3a2ac6f..ba2607e1ad 100644 --- a/pcbnew/footprint_editor_settings.cpp +++ b/pcbnew/footprint_editor_settings.cpp @@ -29,8 +29,6 @@ #include #include -extern const char* traceSettings; - ///! Update the schema version whenever a migration is required const int fpEditSchemaVersion = 1;