From 758ac9006901c92210bfc49930a296628f2aa10c Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 30 Jun 2024 18:39:59 +0200 Subject: [PATCH] SIMULATOR_FRAME_UI: catch all nlohmann::json::xxx errors. Previously, only nlohmann::json::type_error was captured, and other errors were not handled, creating unhandled exception issue when reading broken *.wks files. From master branch. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18309 --- eeschema/sim/simulator_frame.cpp | 1 + eeschema/sim/simulator_frame_ui.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/eeschema/sim/simulator_frame.cpp b/eeschema/sim/simulator_frame.cpp index f9ca474e68..7e3b814723 100644 --- a/eeschema/sim/simulator_frame.cpp +++ b/eeschema/sim/simulator_frame.cpp @@ -541,6 +541,7 @@ bool SIMULATOR_FRAME::LoadWorkbook( const wxString& aPath ) return true; } + DisplayErrorMessage( this, wxString::Format( _( "Unable to load or parse file %s" ), aPath ) ); return false; } diff --git a/eeschema/sim/simulator_frame_ui.cpp b/eeschema/sim/simulator_frame_ui.cpp index 40b69a8d91..49c85fbdcc 100644 --- a/eeschema/sim/simulator_frame_ui.cpp +++ b/eeschema/sim/simulator_frame_ui.cpp @@ -2079,6 +2079,29 @@ bool SIMULATOR_FRAME_UI::loadJsonWorkbook( const wxString& aPath ) return false; } + catch( nlohmann::json::type_error& error ) + { + wxLogTrace( traceSettings, wxT( "Json type error reading %s: %s" ), aPath, error.what() ); + + return false; + } + catch( nlohmann::json::invalid_iterator& error ) + { + wxLogTrace( traceSettings, wxT( "Json invalid_iterator error reading %s: %s" ), aPath, error.what() ); + + return false; + } + catch( nlohmann::json::out_of_range& error ) + { + wxLogTrace( traceSettings, wxT( "Json out_of_range error reading %s: %s" ), aPath, error.what() ); + + return false; + } + catch( ... ) + { + wxLogTrace( traceSettings, wxT( "Error reading %s" ), aPath ); + return false; + } return true; }